0

I want to create a new registry using this code:

Dim r As RegistryKey = Registry.LocalMachine.OpenSubKey(RegEditAuditor, True)
r.SetValue("Actualizar", StartupPath + "\Actualizar")
RegActualizar = r.GetValue("Actualizar", "")
r.Close()

But when I execute my application I get an error that I think its about permission, because if I execute as administrator it works fine.

djv
  • 15,168
  • 7
  • 48
  • 72

1 Answers1

0

You are trying to edit LOCAL MACHINE registry,
Which requires administrative access,
So you have 2 choices here:

1) Make assembly always RUN AS ADMINISTRATOR

You can make your assembly to always RUN AS ADMINISTRATOR.,
By adding the Manifest File

Right click your project file on the Solution Explorer,
Select Add, then New item (or CTRL+SHIFT+A),
There you can find Application Manifest File,



Change the <requestedExecutionLevel> element to:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

2) Change LocalMachine to CurrentUser (Recommended)

Dim r As RegistryKey = Registry.CurrentUser.OpenSubKey(RegEditAuditor, True)
r.SetValue("Actualizar", StartupPath + "\Actualizar")
RegActualizar = r.GetValue("Actualizar", "")
r.Close()
Sorry IwontTell
  • 466
  • 10
  • 29