Registry.GetValue always return null

后端 未结 6 1203
刺人心
刺人心 2020-12-08 15:26

I have the following key in my registry:

under:HKEY_LOCAL_MACHINE\\SOFTWARE\\RSA I have value object call - WebExControlManagerPath and its

6条回答
  •  悲哀的现实
    2020-12-08 16:26

    You don't access the HKEY_LOCAL_MACHINE hive the same way you do in C# as you would in batch scripting. You call Registry.LocalMachine, as such:

            RegistryKey myKey = Registry.LocalMachine.OpenSubKey( @"Software\RSA", false);
            String value = (String)myKey.GetValue("WebExControlManagerPth");
    
            if (!String.IsNullOrEmpty(value))
            {
                ProcessAsUser.Launch(ToString());
            }
    

    Update:

    If it returns null, set your build architecture to Any CPU. The operating system may virtualize 32-bit and 64-bit registries differently. See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa965884%28v=vs.85%29.aspx, Reading 64bit Registry from a 32bit application, and http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072%28v=vs.85%29.aspx.

提交回复
热议问题