Monday, November 25, 2013

Get Registry key value for 32 and 64 bit machines


Here is the snippet that pulls a LOCALMACHINE\SOFTWARE
public static string GetRegistryKey(string keyName)
{
    string currentKey = String.Empty;
    using (RegistryKey key32 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\JobTracker"))
    {
        if (key32 != null)
        {
            currentKey = key32.GetValue(keyName).ToString();
        }
        else
        {
            using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
            using (var key64 = hklm.OpenSubKey(@"SOFTWARE\JobTracker"))
           {
         currentKey = key64.GetValue(keyName).ToString();
            }
        }
    }            
    return currentKey;
}

Related Posts :



0 comments on "Get Registry key value for 32 and 64 bit machines"

Add your comment. Please don't spam!
Subscribe in a Reader

Post a Comment