Nikhil Kaveth
Nikhil Kaveth

Reputation: 103

querying registry using wmi query in windows

I need to get installed software in as shows in Uninstall Program in control panel. So i used Win32_RegistryAction class for querying in vb script. But still i could not query a particular key and it hangs. Here is the piece of code which i used. Please help me how to get installed software details using wmi query.
Thanks in advance

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

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

Upvotes: 1

Views: 20287

Answers (2)

Nikhil Kaveth
Nikhil Kaveth

Reputation: 103

Here i am answering to my own question. Thank You RRUZ for lead me in a right way. Here i have solution for this problem. Now i am able to get all installed software which are showing the uninstall program in windows. Sample code is giving here

Dim count
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
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}!\\.\root\default:StdRegProv")
strKeyPath = "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
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

Here the path Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall is only applicable for Windows 7 or above.

Upvotes: 0

RRUZ
RRUZ

Reputation: 136391

You are using the wrong WMI class, you must use the StdRegProv class instead, for examples about how use this try the MSDN documentation (WMI Tasks: Registry).

Upvotes: 3

Related Questions