Wednesday, 6 February 2013

C#.NET to read Registry value from machnie

Get Registry value from Machine

You can use following method read registry value from mahcine, it will return registry value based on input parameter.

C# Method

public string getRegistryValue(string subKeyPath, string KeyName)
{

// Create value variablestring regValue = null;
try{// Opening the registry keyRegistryKey regLocalKey = Registry.LocalMachine;
// Open a subKey as read-onlyRegistryKey regKey = regLocalKey.OpenSubKey(subKeyPath, 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(KeyName.ToUpper()); }

 }

catch (Exception ex){

regValue =null;}
return regValue ;

}

Test the above method :

string regValue = getRegistryValue(@"Software\Microsoft\Internet Explorer", "W2kVersion");

No comments:

Post a Comment