views:

336

answers:

1

vs2008, c#: First time my winforms app runs it needs to create a setting in HKLM\Software. Obviously a permissions problem, but the requirement is that the user may not have admin rights, and setting permissions on the registry manually is not possible for the end user. I could create keys during install, but is there any way to do this from the program?

RegistryKey key = Registry.LocalMachine.CreateSubKey(@"Software\MyCompany\MyApp 1.0");

Just testing the app from vs2008 gives this error: Access to the registry key 'HKEY_LOCAL_MACHINE\Software\MyCompany\MyApp' is denied.

If I run it as administration no errors.

A: 

The only way to do it from your program is to execute the code that writes to the registry under an account that has sufficient permissions. You may check out this article which gives an example of impersonating a user. There are some security considerations to take into account with this method so IMHO the best way is to perform this operation during program install.

Darin Dimitrov

related questions