VB write to Local Machine Registry

1.6k views Asked by At

I am trying to write to the windows registry using visual basic. I want to write to HKEY_LOCAL_MACHINE but keep getting access denied, even when my setup program runs as administrator.

The path and code I am using is this:

My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R19.1\ACAD-D001\Variables\SECURELOAD", "(Default)", "0")
1

There are 1 answers

0
Sonorpearl On

Normally there are two ways to work around this issue

  • Change the app's manifest to include: <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> Or try including: requireAdministrator
  • Run the program with Administrative priviledges (different than running a program as an account which has Administrative priviledges)

If everything failes try this: "Full Control" access was only given to the TrustedInstaller group, so grant "Full Control" to the users in the Administrators group as well. Eitherway you give them that right manually or you could try the following:

Start 'regedit' with SYSTEM privileges using Sysinternals PsExec tool [psexec -si regedit] and navigate to the key you wish to manipulate using your program and use [Edit -> Permissions] to grant write access to yourself.

Here is a fairly detailed article on UAC. It's not 100% programming material but it gives a good explanation: http://technet.microsoft.com/en-us/library/cc709691.aspx

And if you need more help, you can try looking at this Article: http://www.codeproject.com/Articles/3881/Working-with-Windows-Registry-using-VB-NET