使用C#获取access database engine(ACE) 注册表键值及键值重复问题

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))

这段代码的作用是什么?这就弄成了“知其然不知其所以然”了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值