Phreak3eb
asked on
Retrieve Installed Software 64-bit Windows Using WMI
I'm trying to retrieve all installed software on our Windows machines using C#. I can't seem to find a way to do this on 64-bit versions of Windows. All the examples I've found so far use VBScript, which, generally, I can convert them to C#, however, I'm having a heck of a time converting this script I've found by David Gardiner (http://davidgardiner.blogspot.com/2007/03/listing-installed-applications-on-vista.html) that DOES work. Can anyone help me convert this script to C# or point me in the direction to do this from scratch in C#?
strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 32
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")
WScript.Echo "32-bit Applications"
WScript.echo "-------------------"
Call GetApplications
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")
WScript.Echo "64-bit Applications"
WScript.echo "-------------------"
Call GetApplications
Sub GetApplications
' Use ExecMethod to call the GetStringValue method
Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
Set Outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams,,objCtx)
For Each strSubKey In Outparams.snames
Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "Software\Microsoft\Windows\CurrentVersion\Uninstall\" & strSubKey
Inparams.Svaluename = "DisplayName"
set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
if ("" & Outparams.sValue) = "" then
'wscript.echo strSubKey
Else
wscript.echo Outparams.SValue
End iF
'Inparams.Svaluename = "QuietDisplayName"
'set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
'wscript.echo Outparams.SValue
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
Vee_Mod
Community Support Moderator
ASKER
Open in new window