23 July 2008

Registry Key : Add & Read in VS 2005

Shimul, my friend, suggested me to add some advanced feature of creating setup project like registry key. This blog contains basic steps of adding a registry key from setup project as well as reading a registry key value from the program.

How to see the registry keys:

Click on Start Menu > Run > regedit [enter]. Here you will see the following.

You can find a short description on registry key here http://www.dotnetheaven.com/Uploadfile/sushmita_kumari/RegistryKeys102212006232904PM/RegistryKeys1.aspx

How to Add Registry Keys from Setup Project:

  1. In Solution Explorer, right click on Setup Project.


  2. Click on View > Registry.
  3. Expand the tree view of Registry key (setup) in the left side where you want to add a key. Here we will add a key in following directory.


  4. Right click on [Manufacturer] > New > String Value.
  5. Rename the newly added key name. Set its value from it’s properties.

How to modify Manufacturer:

  1. Go to properties of Setup Project.
  2. Change the field Manufacturer

You can see the Registry value after installing which is like below:



Sample Code to Read Registry Key:

using Microsoft.Win32;

string v = getRegistryKeyValue(@"SOFTWARE\BUET", "MyKey");

MessageBox.Show("Key value : " + v);

private string getRegistryKeyValue(string keyPath, string keyName)

{

try

{

RegistryKey rk = Registry.CurrentUser.OpenSubKey(keyPath);

string s = (string)(rk.GetValue(keyName));

rk.Close();

return s;

}

catch (Exception ex)

{

return null;

}

}

3 Comments:

Shimul said...

thanks buddy :)

Shimul said...

i want to add an uninstall link in the User's Program Menu, can you help me with this?

Scott said...

This is an awesome post. Figured it out.

 

© 2007 t!ps n tr!cks: Registry Key : Add & Read in VS 2005



Template unik dari rohman


---[[ Skip to top ]]---