views:

59

answers:

2

I have a c# windows client app packaged using ClickOnce. Using c# how can I programmatically get the registry entry for that application? As I am wanting to write a registry entry for a child app NEAR the same location

A: 

AFAIK, the only registry key ClickOnce might create is the key related to displaying the application in the system's Add/Remove Programs control panel for uninstall purposes. I doubt this is what you want. It is not appropriate to write configuration settings there. Thus, there is no existing "registry entry for that application" for you to get.

If you want to store settings, there is a whole "application settings" infrastructure for this. It is file-based, not registry-based. It play well with ClickOnce.

See: http://msdn.microsoft.com/en-us/library/0zszyc6e.aspx

You can, of course, create a registry entry yourself in any part of the registry where the user has suitable access. The class for doing this is Microsoft.Win32.Registry: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx

A good choice of registry location would be HKEY_CURRENT_USER\Software\YourCompanyName\YourProductName.

binarycoder
A: 

U can define and get a registry key like this.

        // Define a key
        Microsoft.Win32.RegistryKey key;
        key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("AppName");
        key.SetValue("AppName", "Cracker");
        key.Close();


        // Retrieving data
        object keyData = Microsoft.Win32.Registry.CurrentUser.GetValue("AppName");

Read more from http://msdn.microsoft.com/en-us/library/h5e7chcf.aspx

Wonde
I understand that this is just a simple example, but readers please be careful as to what registry key you choose. Creating directly under HKEY_CURRENT_USER as shown above is not good form. Standard practice would be something like `HKEY_CURRENT_USER\Software\YourCompanyName\YourProductName`.
binarycoder