C# Reading the registry: ProductID returns null in x86 targeted app. “Any CPU” works fine

前端 未结 3 875
抹茶落季
抹茶落季 2021-01-11 18:53

I have recently moved to a W7 64bit machine with VS 2010. My project is set to run on Any CPU. When I change this to be targeted at x86 I noticed s

3条回答
  •  青春惊慌失措
    2021-01-11 19:20

    Some registry keys are redirected by WOW64. More information on this topic is available on MSDN http://msdn.microsoft.com/en-us/library/aa384232(v=vs.85).aspx

    If you really want to always access the x64 node (.Net4) :

      RegistryKey localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
      RegistryKey windowsNTKey = localMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion");
      object productID = windowsNTKey.GetValue("ProductId");
    

提交回复
热议问题