Wednesday, September 1, 2010

Registry Access | C#

Registry class (which is part of the namespace Microsoft.Win32) in .NET exposes CurrentUser, Local Machine etc.. keys by default and so it is not needed to mention the keys beginning with the following:


For instance use the the below code to access the keys from the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\System Center Essentials\2.0\Setup\Components\Server-Version
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("\\SOFTWARE\\Microsoft\\System Center Essentials\\2.0\\Setup\\Components");
if (registryKey != null)
{ 
    string serverVersion = Convert.ToString(registryKey.GetValue("Server-Version"));
}

No comments :

Post a Comment