Save and Get a Registry Value in 'HKEY_LOCAL_M

2019-09-20 18:19发布

In my VB.NET project I want to save and get a registry value in "HKEY_LOCAL_MACHINE\Software" but I am only able to save and get it in "HKEY_LOCAL_MACHINE" but not software.

Here is my code:

For setting the value

My.Computer.Registry.LocalMachine.SetValue("Study", "1")

For getting the value

Dim RegistryCheck As String = My.Computer.Registry.LocalMachine.GetValue("Study")

1条回答
2楼-- · 2019-09-20 18:44

You have to verify if you have the permission to write (and also read) from HKEY_LOCAL_MACHINE. If you can't get the required permissions (which is quite possible), opt for HKEY_CURRENT_USER (My.Computer.Registry.CurrentUser). Anyway, you have to specify what kind of permissions you're requiring: Read/ReadWrite. See the overloads of the OpenSubKey() method. Two of them let's you specify these requirements. If/When you are granted the permission, create the subkey (CreateSubKey()) and then set a key value inside it (with SetValue()), specifying a value type with RegistryValueKind.

查看更多
登录 后发表回答