Save and Get a Registry Value in 'HKEY_LOCAL_MACHINE\Software' using VB.NET

為{幸葍}努か 提交于 2019-12-12 06:38:53

问题


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:


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.



来源:https://stackoverflow.com/questions/50601755/save-and-get-a-registry-value-in-hkey-local-machine-software-using-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!