ikantspelwurdz
Well-known member
- Joined
- Dec 8, 2009
- Messages
- 49
- Programming Experience
- 1-3
Here's a drilled-down version of what I'm trying to do.
On Windows XP, this works fine. On my Windows 7 64 machine, if I simply run the executable normally, it throws an exception - something along the lines that access to HKCU\SOFTWARE\FOO\BAR is denied. I'm typing this from my XP machine so I don't have the exact message at the moment, but that is the gist of it.
Now, if I run the executable in administrator mode, then it works fine. The intuitive explanation is that writing to HKCU requires elevated privileges. But I've run Steam on the Win7 machine, and I'm pretty sure Steam writes to HKCU without needing elevated privileges. Just running it while logged in as an admin is enough. So, is it possible for me to write a program that creates keys in HKCU too, without needing the user to manually invoke admin mode?
VB.NET:
Module Module1
Sub Main()
Dim regType As Microsoft.Win32.RegistryValueKind = Microsoft.Win32.RegistryValueKind.String
Dim regKey As String = "SOFTWARE\FOO\BAR"
Dim newKey As Microsoft.Win32.RegistryKey
Try
newKey = My.Computer.Registry.LocalMachine.CreateSubKey(regKey)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Module
On Windows XP, this works fine. On my Windows 7 64 machine, if I simply run the executable normally, it throws an exception - something along the lines that access to HKCU\SOFTWARE\FOO\BAR is denied. I'm typing this from my XP machine so I don't have the exact message at the moment, but that is the gist of it.
Now, if I run the executable in administrator mode, then it works fine. The intuitive explanation is that writing to HKCU requires elevated privileges. But I've run Steam on the Win7 machine, and I'm pretty sure Steam writes to HKCU without needing elevated privileges. Just running it while logged in as an admin is enough. So, is it possible for me to write a program that creates keys in HKCU too, without needing the user to manually invoke admin mode?