Manipulating the registry from a Click Once App
I have a couple applications that store data in the registry for persistence. It works great when running in Windows XP, but since upgrading to Windows 7 I've noticed that it fails, basically saying that the permissions are inadequate.
If I disable the UAC it seems to work fine, but I don't want to do that.
Dim regKey As RegistryKey
Try
regKey = Registry.LocalMachine.OpenSubKey("Software\TagLookup", True)
If regKey Is Nothing Then
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
regKey.CreateSubKey("TagLookup")
regKey.Close()
Else
PrinterDeviceName = regKey.GetValue("PrinterName")
regKey.Close()
End If
Catch e开发者_Go百科x As Exception
MsgBox(ex.ToString, MsgBoxStyle.Exclamation)
End Try
You should be writing to HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE.
精彩评论