WMI:Windows Management Instrumentation 视窗管理仪器
MSDN:http://msdn.microsoft.com/en-us/library/aa393664(v=vs.85).aspx
通过 WMI 的 StdRegProv 类 可以获得或更改注册表
StdRegProv 类 的方法:
CheckAccess 检查用户是否有访问权限
CreateKey 创建一个子键
DeleteKey 删除一个子键
DeleteValue 删除一个命名的键值
EnumKey 枚举包含的子键
EnumValue 枚举一个键的已命名的键值
GetBinaryValue 获得键值的二进制值
GetDWORDValue 获得键值的DWORD值
GetExpandedStringValue 获得键值的可扩展字符串值
GetMultiStringValue 获得键值的多字符串值
GetQWORDValue 获得键值的QWORD值(Windows Server 2003、XP、2000 及以下版本不可用)
GetSecurityDescriptor 获得一个键的安全描述(Windows Server 2003、XP、2000 及以下版本不可用)
GetStringValue 获得键值的字符串值
SetBinaryValue 设置键值的二进制值
SetDWORDValue 设置键值的DWORD值
SetExpandedStringValue 设置键值的可扩展字符串值
SetMultiStringValue 设置键值的多字符串值
SetQWORDValue 设置键值的QWORD值(Windows Server 2003、XP、2000 及以下版本不可用)
SetSecurityDescriptor 设置一个键的安全描述(Windows Server 2003、XP、2000 及以下版本不可用)
SetStringValue 设置一个键值的字符串值
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Sub test()
Dim strKeyPath$
strKeyPath = "Software\Microsoft\Office\" & Application.Version & "\Excel\"
Debug.Print ExistsKeyPath(HKEY_CURRENT_USER, strKeyPath)
End Sub
Function ExistsKeyPath(ByVal lngKeyBase&, ByVal strKeyPath$) As Boolean
Dim objReg As Object, strComputer$
strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objReg.CheckAccess lngKeyBase, strKeyPath, &H1, ExistsKeyPath
Set objReg = Nothing
End Function