windows下使用wmi查询注册表



我需要在控制面板中卸载程序中安装软件。所以我使用Win32_RegistryAction类在vb脚本中查询。但我仍然不能查询一个特定的键,它挂起。这是我使用的代码。请帮助我如何获得安装软件的详细信息使用wmi查询。
提前致谢

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" _
& strComputer & "rootcimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_RegistryAction where key ='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' and Root=2 ")
For Each objComputer in colSettings 
Wscript.Echo "Display Name: " & objComputer.DisplayName    
Next

你正在使用错误的WMI类,你必须使用StdRegProv类代替,关于如何使用这个例子,请尝试MSDN文档(WMI任务:注册表)

我在这里回答我自己的问题。谢谢你RRUZ指引我走正确的道路。这里我有解决这个问题的办法。现在我能够得到所有安装的软件显示卸载程序在windows。示例代码在这里给出

Dim count
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\.rootdefault:StdRegProv")
strKeyPath = "SoftwareMicrosoftWindowsCurrentVersionUninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames
count = 0
For i=0 To UBound(arrValueNames)
StrText = arrValueNames(i)
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "DisplayName",strName
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "DisplayVersion",strVersion
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "InstallLocation",strLocation
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "InstallDate",strDate
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "SystemComponent",strSystemComponent
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "WindowsInstaller",strWindowsInstaller
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "UninstallString",strUninstallString
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "ReleaseType",strReleaseType
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "ParentKeyName",strParentKeyName
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "Publisher",strPublisher
if isNull(strSystemComponent) then
if isNull(strWindowsInstaller) then
if not isNull(strUninstallString) then
if isNull(strReleaseType) then
if isNull(strParentKeyName) then
if not isNull(strName) then
printKeyValue "Win32_Product.PackageName[" & count & "]", StrName
printKeyValue "Win32_Product.Version[" & count & "]", StrVersion
printKeyValue "Win32_Product.InstallLocation[" & count & "]", strLocation
printKeyValue "Win32_Product.InstallDate[" & count & "]", strDate
printKeyValue "Win32_Product.Publisher[" & count & "]", strPublisher
printKeyValue "Win32_Product.WindowsInstaller[" & count & "]", strWindowsInstaller
printKeyValue "Win32_Product.UninstallString[" & count & "]", strUninstallString
printKeyValue "Win32_Product.ReleaseType[" & count & "]", strReleaseType
printKeyValue "Win32_Product.ParentKeyName[" & count & "]", strParentKeyName
count = count + 1
end if
end if
end if
end if
end if
end if
Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\.rootdefault:StdRegProv")
strKeyPath = "SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames
For i=0 To UBound(arrValueNames)
StrText = arrValueNames(i)
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "DisplayName",strName
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "DisplayVersion",strVersion
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "InstallLocation",strLocation
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "InstallDate",strDate
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "SystemComponent",strSystemComponent
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "WindowsInstaller",strWindowsInstaller
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "UninstallString",strUninstallString
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "ReleaseType",strReleaseType
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "ParentKeyName",strParentKeyName
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "" & arrValueNames(i), "Publisher",strPublisher
if isNull(strSystemComponent) then
if isNull(strWindowsInstaller) then
if not isNull(strUninstallString) then
if isNull(strReleaseType) then
if isNull(strParentKeyName) then
if not isNull(strName) then
printKeyValue "Win32_Product.PackageName[" & count & "]", StrName
printKeyValue "Win32_Product.Version[" & count & "]", StrVersion
printKeyValue "Win32_Product.InstallLocation[" & count & "]", strLocation
printKeyValue "Win32_Product.InstallDate[" & count & "]", strDate
printKeyValue "Win32_Product.Publisher[" & count & "]", strPublisher
printKeyValue "Win32_Product.WindowsInstaller[" & count & "]", strWindowsInstaller
printKeyValue "Win32_Product.UninstallString[" & count & "]", strUninstallString
printKeyValue "Win32_Product.ReleaseType[" & count & "]", strReleaseType
printKeyValue "Win32_Product.ParentKeyName[" & count & "]", strParentKeyName
count = count + 1
end if
end if
end if
end if
end if
end if
Next
Function printKeyValue(key, value)
Wscript.Echo key & "=>" & value
End Function

这里的路径SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall仅适用于Windows 7或以上版本。

最新更新