Monday, 11 March 2013

Get the RegisteryKey value

Following sample code can be used to get RegisteryKey value based on keyPath and KeyName

public static String GetRegistryValue(String regKeyPath, String regKeyName)

// Create value variablestring regValue = null;
// Opening the registry keyRegistryKey rk = Registry.LocalMachine;
// Open a subKey as read-onlyRegistryKey regKey = rk.OpenSubKey(regKeyPath, RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.FullControl);
// If the RegistrySubKey does existif (regKey != null){

// If the RegistryKey exists get its value or null is returned.regValue = (string)regKey.GetValue(regKeyName.ToUpper());}

return regValue;}

catch (Exception ex){

throw ex;}

No comments:

Post a Comment