0

I want to write a Value in my registry. Im using C# 4.0. Im using following code.

RegistryKey rk = baseRegistryKey;

RegistryKey sk1 = rk.CreateSubKey(subKey);

sk1.SetValue(KeyName.ToUpper(), Value);

this subKey value is "SOFTWARE\POS"

This worked fine in my previous machine. It was Windows 7, 32 bit Operating System. Now im using Windows 7, 64 bit Operating System. Now this program is generates following error when execute RegistryKey sk1 = rk.CreateSubKey(subKey); line.

"Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\POS' is denied."

I logged as administrator too. But CreateSubKey method is under Microsoft.Win32 Name space.

Please help. Thanks in advance.

Charitha
  • 517
  • 2
  • 7
  • 20
  • possible duplicate of [How to force C# App to run as administrator on Windows 7](http://stackoverflow.com/questions/2818179/how-to-force-c-sharp-app-to-run-as-administrator-on-windows-7) – Hans Passant Jun 24 '12 at 14:37

1 Answers1

0

You need to let your application run as administrator. If you want to force your application to run as administrator, you will need to add a manifest file to your project and add the following line to the manifest file:

<requestedExecutionLevel level="requireAdministrator" />

Hope this was useful for you and solve your problem.

razlebe
  • 7,134
  • 6
  • 42
  • 57
Manar Husrieh
  • 491
  • 1
  • 5
  • 16