'WMIGetProd.VBS 'v1.0 November 2001 'Jeffery Hicks 'jhicks@quilogy.com http://www.quilogy.com 'USAGE: cscript|wscript wmigetprod.vbs [servername username password] 'DESC: Create a comma delimited file of applications 'installed with the Windows Installer. If you don't specify 'a server name, the default is the local computer. 'You can also specify credentials to be used on the remote system. 'If you don't specify all the parameters, you will be prompted. 'The password is case-sensitive dim oLocator, oSvc, oFSO, oFile dim oNet const ForWriting=2 const ForAppending=8 On Error Resume Next set oNet=CreateObject("Wscript.Network") strTitle="Windows Installer Products" strNamespace="root\cimv2" Select Case wscript.Arguments.Count Case 0 strPC=oNet.ComputerName strUser="" strPassword="" Case 3 strPC=wscript.Arguments(0) strUser=wscript.Arguments(1) strPassword=wscript.Arguments(2) Case Else strPC=Inputbox("Enter a computername to query. DO NOT ENTER THE LOCAL COMPUTER NAME!!!",strTitle,wscript.Arguments(0)) If strPC="" Then wscript.echo "Nothing entered for username or you cancelled" wscript.quit End If strUser=Trim(Inputbox("Enter a user name that has admin rights on " & strPC,strTitle,oNet.UserName)) If strUser="" Then wscript.echo "Nothing entered for username or you cancelled" wscript.quit End If strPassword=Trim(Inputbox("Enter in the appropriate password which is CaSe SensiTive",strTitle,"password")) If strPassword="" Then wscript.echo "Nothing entered for password (blank passwords not allowed) or you cancelled" wscript.quit End If End Select Set oLocator=CreateObject("WbemScripting.SWbemLocator") Set oSvc=oLocator.ConnectServer(strPC,strNamespace,strUser,strPassword) If err.number<>0 Then wscript.echo "There was an error connecting to " & UCASE(strPC) & VBCRLF & _ "Make sure you specified the correct credentials and/or a valid server name." & VBCRLF & _ "Error #" & err.number & " - " & err.description wscript.quit End If 'Where do you want to create the .csv file? 'The default is to use the computername, but if you were going to 'run this against multiple computers, you might want to save the 'information to a single file. If the file already exists, the 'default action is to append information. output=".\installedproducts.csv" set oFSO=CreateObject("Scripting.FileSystemObject") if oFSO.FileExists(output) Then set oFile=oFSO.OpenTextFile(output,ForAppending) Else set oFile=oFSO.CreateTextFile(output) 'header shows computername, product name, product vendor, 'product version, when the product was installed and when 'you ran this audit oFile.WriteLine "Computer,Product,Vendor,Version,InstallDate,AuditDate" End if for each prod in oSvc.InstancesOf("Win32_Product") strYr=Left(prod.InstallDate,4) strMo=Mid(prod.InstallDate,5,2) strDy=Right(prod.InstallDate,2) strInstalled=strMo&"/"&strDy&"/"&strYr oFile.WriteLine strPC & "," & prod.Name & "," & prod.Vendor & _ "," & prod.Version & "," & strInstalled & "," & DATE Next wscript.Echo "See " & output & " for results" oFile.Close set oLocator=Nothing set oSvc=Nothing set oFSO=Nothing set oFile=Nothing 'EOF