0
votes

I've created a .net program that runs as a service. The service runs as the Local System Account. I would like to learn about how to use the Windows Registry to store settings for the program.

I've read about how to use the .net classes to read and write values to the registry.

However, I understand that upon installation of the program, my MSI installer will need to create the registry keys where the values will be stored.

How do I determine the appropriate place to create the new registry key?

Update: In this particular case, I the program should always run as the Local System account. However, in the case that it runs as another account I want it to use the same settings. Furthermore, I would like to use a configuration tool to modify the settings which will run as the identity of the logged in user.

1
Please go easy on me. I have very little experience with using the registry so far :-)Vivian River
Maybe use HKLM\SOFTWARE\YourProgram or HKCU depending on what they are needed for.Bali C
HKLM\SOFTWARE\YourCompany\YourProgram or in HKCU if is a per user settingDavide Piras
Primary consideration here is whether it is acceptable or desired to have this config program ask for UAC elevation. You have a lot less options if you don't want this.Hans Passant
Since you are using .Net to create this, is there any specific reason you would want to use the registry for configuration? the .config of .Net could probably support your needs and reduces dependency on the registry (which is a performance/security sensitive option).Marvin Smit

1 Answers

0
votes

Since you are not making your main application's settings user-centric, then you'll want to save to HKEY_LOCAL_MACHINE\Software\YourCompanyName\YourApplicationName.

From there, I'd create deeper keys depending on how the application is designed. Form specific settings would go in a subkey with the form's name. General application settings would go in my application key. In the end, it doesn't matter to anyone else, so long as it makes sense to you.