1、本意是想获取本机是否安装有ACE ,以及安装后的版本问题,结果未知原因,没获取到正确值(猜测是获取到了重复值,只不过最后得出的是最后一个值(office15),被覆盖了??)。
ACE 本机的可能位置
string aceRegKey64 = @"CLSID\{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32";
string aceRegKey32 = @"WOW6432Node\CLSID\{3BE786A0-0366-4F5C-9434-25CF162E475E}\InprocServer32";
2、上代码
public static (bool aceExsist ,string aceKeyValue) aceRegKeyExisist(string keyPath)
{
using (RegistryKey aceKey = Registry.ClassesRoot.OpenSubKey(keyPath))
{
if (aceKey != null)
{
if (aceKey.GetValue(null) != null)
{
object ace64Pth = aceKey.GetValue(null);
if (System.IO.File.Exists(ace64Pth.ToString()))
{
return (true, ace64Pth + ">存在");
}
else
{
return (true, ace64Pth + ">键值不正确");
}
}
else
{
return (true, "键值为空");
}
}
else
{
return (false, "ACE64注册表 不存在");
}
}
}
3、本机因为多次安装卸载office,导致上述2个位置都有值,但实际使用的是64位置的,即ACE版本应该是OFFICE14结果获取到的是OFFICE15.

4、经过N时间的挣扎……
通过【小艺】找到另外的一条思路,以下代码是正确的
public static (bool aceExsist ,string aceKeyValue) aceRegKeyExisist(string keyPath)
{
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64))
using (RegistryKey aceKey = baseKey.OpenSubKey(keyPath))
{
if (aceKey != null)
{
if (aceKey.GetValue(null) != null)
{
object ace64Pth = aceKey.GetValue(null);
if (System.IO.File.Exists(ace64Pth.ToString()))
{
return (true, ace64Pth + ">存在");
}
else
{
return (true, ace64Pth + ">键值不正确");
}
}
else
{
return (true, "键值为空");
}
}
else
{
return (false, "ACE64注册表 不存在");
}
}
}
问题是解决了,那么问题来了
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64))
这段代码的作用是什么?这就弄成了“知其然不知其所以然”了。

被折叠的 条评论
为什么被折叠?



