使用Excel VBA查找注册表项 [英] Find registry key using Excel VBA

查看:113
本文介绍了使用Excel VBA查找注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查用户是否安装了Microsoft SQL Native Client 2008(sqlncli10)或Native Client 2012(sqlncli11).

I want to check if a user has Microsoft SQL Native Client 2008 (sqlncli10) or Native Client 2012 (sqlncli11) installed.

Dim key As String
Dim myShell As Object
Set myShell = CreateObject("WScript.Shell")

key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion\Version"
'key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion"

Dim strKey As String
strKey = myShell.RegReadkey(key)

寻找本地客户端时,我收到错误消息:

When looking for the native client I receive the error:

注册表项"HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft SQL Server \ SQLNCLI11 \ CurrentVersion \ Version"中的无效根

Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft SQL Server\SQLNCLI11\CurrentVersion\Version"

但是在尝试Windows NT版本时,它可以正常工作.

but when trying the Windows NT version it works fine.

我用HKLM替换了HKEY_LOCAL_MACHINE:但这也不起作用.

I replaced HKEY_LOCAL_MACHINE with HKLM: but that doesn't work either.

编辑

我只是想通了.当我检查注册表时,它存在于64位部分中.但是,VBA检入32位,并且SOFTWARE的根目录变为Wow6432Node.因此,它将在Wow6432Node \ Microsoft \ Microsoft SQL Server中签入,并且该密钥在此处不存在.但是我发现了另一条路径SOFTWARE \ Microsoft \ Microsoft SQL Server Native Client 10或11,它们同时存在于32位和64位中.

I just figured it out I think. When I checked in the registry it exists in the 64-bit section. However VBA checks in 32-bit and the root for SOFTWARE becomes Wow6432Node. So it checks in Wow6432Node\Microsoft\Microsoft SQL Server and the key does not exist there. But I have found another path SOFTWARE\Microsoft\Microsoft SQL Server Native Client 10 alternatively 11 which exist in both 32-bit and 64-bit.

推荐答案

此代码对我有用:

Dim key As String
Dim objShell As Object

Set objShell = CreateObject("WScript.Shell")
key = objShell.RegRead _
    ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLNCLI11\CurrentVersion\Version")

我只是在Excel 2010 VBA编辑器中完成的.

I just did this in the Excel 2010 VBA editor.

这篇关于使用Excel VBA查找注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆