从注册表中读取价值

Tir*_*ada 2 .net c# registry

谷歌今天没有帮助我,所以我需要你的帮助.有可能从注册表中读取值吗?示例此位置 - > HKEY_LOCAL_MACHINE> SOFTWARE> MyKey列是Test键

Har*_*der 11

64位+ 32位

   using Microsoft.Win32;
    public static string GetRegistry()
    {
        string registryValue = string.Empty;
        RegistryKey localKey = null;
        if (Environment.Is64BitOperatingSystem)
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
        }
        else
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
        }

        try
        {
            localKey = localKey.OpenSubKey(@"Software\\MyKey");
            registryValue = localKey.GetValue("TestKey").ToString();
        }
        catch (NullReferenceException nre)
        {

        }
        return registryValue;
    }
Run Code Online (Sandbox Code Playgroud)