接上文:http://www.cnblogs.com/TaiYangXiManYouZhe/p/5086974.html
上代码:
RegistryKey localKey; if (Environment.Is64BitOperatingSystem) localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); else localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); string value = localKey.OpenSubKey(@"SOFTWAREMicrosoftOffice15.0CommonInstallRoot").GetValue("Path").ToString();
很简单,首先,Environment.Is64BitOperatingSystem 判断是否是64位的操作系统。
然后通过注册表打开目录时,传入相应的RegistryView枚举即可。注意:打开注册表时,调用的是OpenBaseKey方法!