x86项目中使用Registry读取key/value的时候,会出现重定向的问题,解决方法如下:
public static string GetMachineGuid() { string guid = string.Empty; try { RegistryView registryView = RegistryView.Default; if (Environment.Is64BitOperatingSystem) registryView = RegistryView.Registry64; else registryView = RegistryView.Registry32; RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView); using (RegistryKey key = localMachine.OpenSubKey("SOFTWARE\Microsoft\Cryptography")) { if (key != null) { guid = key.GetValue("MachineGuid")?.ToString(); _log.I($"MachineGuid: {guid}"); } } } catch (Exception ex) { _log.I($"GetMachineGuid exception: {ex.Message}"); } return guid; }