Win 10 Registry Key Value in Visual Basic

~OSD~ 2,131 Reputation points
2020-10-07T10:25:53.08+00:00

Hi,

I am following this article to create and set the registry key in VB.
how-to-create-a-registry-key-and-set-its-value

It's creating keys as REG_SZ but I would like to create REG_DWORD (32-bit) value, is it possible?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
948 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
975 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Laude 85,676 Reputation points
    2020-10-07T10:29:54.417+00:00

    HI @~OSD~ ,

    Something here might help:
    https://www.vbforums.com/showthread.php?666782-RESOLVED-How-do-I-make-a-REG_DWORD

    My.Computer.Registry.CurrentUser.CreateSubKey("ARandomKey")  
    My.Computer.Registry.SetValue("HKEY_CURRENT_USER\ARandomKey", "ARandomKey", 2011, Microsoft.Win32.RegistryValueKind.DWord)  
    

    ----------

    (If the reply was helpful please don't forget to upvote or accept as answer, thank you)

    Best regards,
    Leon


2 additional answers

Sort by: Most helpful
  1. Castorix31 81,861 Reputation points
    2020-10-07T11:04:07.44+00:00

    You can see the samples from MSDN:

    RegistryKey.SetValue Method

    0 comments No comments

  2. RLWA32 40,861 Reputation points
    2020-10-07T11:22:07.67+00:00

    After reading the documentation for microsoft.win32.registry.setvalue
    consider the following -

       Sub Main()  
           Try  
               Registry.CurrentUser.CreateSubKey("VBRegTest")  
               Registry.SetValue("HKEY_CURRENT_USER\VBRegTest", "String Value", "42")  
               Registry.SetValue("HKEY_CURRENT_USER\VBRegTest", "DWORD Value", 42)  
               'Following line unintentionally creates a string value because numeric value exceeds the capacity of 32 bit DWORD  
               Registry.SetValue("HKEY_CURRENT_USER\VBRegTest", "Unintended String Value", 3000000000)  
               'Following line creates a numeric 64 bit value  
               Registry.SetValue("HKEY_CURRENT_USER\VBRegTest", "QWORD Value", 3000000000, RegistryValueKind.QWord)  
               'Following line will throw an exception because the numeric value cannot fit into the explicitly specified DWORD data type  
               Registry.SetValue("HKEY_CURRENT_USER\VBRegTest", "QWORD Value", 3000000000, RegistryValueKind.DWord)  
           Catch ex As Exception  
               Console.WriteLine("Caught exception - {0}", ex.Message)  
           End Try  
         
       End Sub  
    
    0 comments No comments