I’m using the following code to run my program that writes to the registry
Dim myProcess2 As New System.Diagnostics.Process()
Dim startInfo2 As New ProcessStartInfo
startInfo2.FileName = Application.StartupPath & "\installs\Assistant\RegisterSureFire.exe"
startInfo2.Verb = "runas"
myProcess2.StartInfo = startInfo2
Application.DoEvents()
myProcess2.Start()
Then I have the other file called “RegisterSureFire” that is being ran that actually writes to the registery using the following code:
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Assistant", "C:\SF\Assistant.exe")
This seems to work perfectly fine in Windows Vista/7/8 with the “runas” for administrator, but when you do this in windows XP, that box comes up asking if u want to run it in current user or in admin. Most of my customers are around 50-70 years old, so they have no idea what this is. Also I notice if I just don’t use the “runas” if its on windows xp in general, then I get an “Access Denied” error message when trying to write to the registry.
Can anyone give me advice on writing to the Registry correctly?
I think your code is indeed right, but your application need the rights to modify the registry. This can be achieved under Windows XP with user impersonation.
please, google to find exactly the solution that fits your needs or take a look to this nice article here:
http://www.codeproject.com/Articles/21050/Security-User-Impersonation