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

前端 未结 3 864
抹茶落季
抹茶落季 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:18

    On win64 some registry keys of 32-bit application are stored in Software\Wow6432Node subkey.

    If you want to switch into 64 bit key you can use RegistryView enum as parameter of RegistryKey.OpenBaseKey

    Personally to make code working always in main registry key (not WoW6432) im using such construction:

    RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32)

提交回复
热议问题