Reputation: 1928
The code below fails when running on Windows 7, with default access levels. (This is a C# application, built with Visual Studio 2010). I am writing to HKEY_CurrentUser, which is where I should be allowed to create and read keys.
Do I need to modify my program's manifest? or is there another arcane trick?
Under Windows 7, If you dial down the notify setting on your user account, the code works. But not with the factory setting. Should programmers give up on the registry?
RegistryKey regsoftware = Registry.CurrentUser.OpenSubKey("Software", true);
RegistryKey regsw = regsoftware.CreateSubKey("MyCompanyName");
regsw.SetValue("User", Id);
regsw.SetValue("Pwd", encodeString(Pw));
Thanks, Gerry
Upvotes: 0
Views: 3311
Reputation: 476
By default if you wanna run your app with admin privileges you can try this.
Go to Project->properties->Drop down "Linker" option->Manifest File->in your right pane check "UAC Execution Level" -> choose "requireAdministrator" (I'm using VS2008 hope it should be same in VS2010). Thatz all you have to do.
Upvotes: 1
Reputation: 978
You have to run your program as an administrator. you can check whether an operation needs elevation or not and elevate an operation if needed with the WinAPI CodePack for .NET Framework.
Upvotes: 0