Check for an installed program

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
harry.butts
Posts: 13
Last visit: Thu Aug 28, 2008 6:58 pm

Check for an installed program

Post by harry.butts »

I'm working on a script to check for one installed program. What I have so far is returning everything that's installed. Can someone help me trim it down? I only want to know if Funk is installed or not. In addition, how can I get the output to tell me "Yes, Funk is installed", or "No, Funk isn't installed"?

Thanks for the help. As always, I appreciate it!

Here's what I have so far.

On Error Resume NextDim objWMIServiceDim colFilesDim objTextfileDim objFSODim strcomputerDim sLogFileset oLogOutput = nothing
Dim objWriteFileConst ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:PCList.txt",1)
Set colFeatures = objWMIService.ExecQuery("Select * from Win32_SoftwareFeature where name like Funk")
Set objWriteFile = objFSO.OpenTextFile("c:FunkInstalled.txt", ForWriting, True)
Do Until objTextFile.AtEndOfStream strcomputer = objTextFile.Readline Set objShell = CreateObject("WScript.Shell") Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strcomputer) strPingResults = LCase(objScriptExec.StdOut.ReadAll) If InStr(strPingResults, "reply from") Then objWriteFile.WriteLine("Host Name: " & strcomputer)
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colFeatures = objWMIService.ExecQuery _ ("Select * from Win32_SoftwareFeature") objFile.WriteLine "Name: " & objWMIService.Name For Each objFeature in colfeatures objWriteFile.WriteLine"Install State: " & objFeature.InstallState objWriteFile.WriteLine "Product Name: " & objFeature.ProductName objWriteFile.WriteLine "Funk Status " & objNicConfig.IndexobjFeature.ProductName" ') For Each strIPAddress In objNicConfig.IPAddress objWriteFile.WriteLine(" " & strIPAddress) Next
User avatar
harry.butts
Posts: 13
Last visit: Thu Aug 28, 2008 6:58 pm

Check for an installed program

Post by harry.butts »

I'm working on a script to check for one installed program. What I have so far is returning everything that's installed. Can someone help me trim it down? I only want to know if Funk is installed or not. In addition, how can I get the output to tell me "Yes, Funk is installed", or "No, Funk isn't installed"?

Thanks for the help. As always, I appreciate it!

Here's what I have so far.

On Error Resume NextDim objWMIServiceDim colFilesDim objTextfileDim objFSODim strcomputerDim sLogFileset oLogOutput = nothing
Dim objWriteFileConst ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("c:PCList.txt",1)
Set colFeatures = objWMIService.ExecQuery("Select * from Win32_SoftwareFeature where name like Funk")
Set objWriteFile = objFSO.OpenTextFile("c:FunkInstalled.txt", ForWriting, True)
Do Until objTextFile.AtEndOfStream strcomputer = objTextFile.Readline Set objShell = CreateObject("WScript.Shell") Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strcomputer) strPingResults = LCase(objScriptExec.StdOut.ReadAll) If InStr(strPingResults, "reply from") Then objWriteFile.WriteLine("Host Name: " & strcomputer)
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colFeatures = objWMIService.ExecQuery _ ("Select * from Win32_SoftwareFeature") objFile.WriteLine "Name: " & objWMIService.Name For Each objFeature in colfeatures objWriteFile.WriteLine"Install State: " & objFeature.InstallState objWriteFile.WriteLine "Product Name: " & objFeature.ProductName objWriteFile.WriteLine "Funk Status " & objNicConfig.IndexobjFeature.ProductName" ') For Each strIPAddress In objNicConfig.IPAddress objWriteFile.WriteLine(" " & strIPAddress) Next
User avatar
harry.butts
Posts: 13
Last visit: Thu Aug 28, 2008 6:58 pm

Check for an installed program

Post by harry.butts »

Thanks for the quick reply, jvierra!

Please understand that I'm just a rookie, and bear with me if I ask seemingly dumb questions.

When you say, "Try starting with the code below...", would I add that to what I already have, and if so, do I put it at the beginning or the end? Or will your script replace mine?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Check for an installed program

Post by jvierra »

Harry

Well. You'll have to do a little work to try and understand the code I have posted.

You are looking for installed software. This code will create a comma separted file of all software elements reportable by WMI. You can then look in the file for the software by hand or use a Excel or some other program to search the file.

What is it that you are trying to do/

The code you posted is just a bunch of scripts stuck together with no reason or sense that I can see. Many pieces are incomplete or in teh wrong order.

If you are looking for a piece of software named "funk" then add "where name='funk'" to the WMI query and that is all it will look for.

Here is a simple query for "funk".

Code: Select all

	

	
GetSoftwareItem "myhost", "Funk"
	

Function GetSoftwareItem( sComputer,  item )
	
    Dim wmi, features, feature
    Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!" & sComputer & "rootcimv2")
    Set features = wmi.ExecQuery("Select * from Win32_SoftwareFeature where ProductName='" & item & "'")
    WScript.Echo  "Name" & vbTab & "ProductName" & vbTab & "Install State" & vbTab & "Vendor"
    For Each feature in features
        With feature
            WScript.Echo feature.Name & vbTab &  feature.ProductName & vbTab &  feature.InstallState & vbTab & feature.Vendor 
        End With
    Next
	

End Function
	

Of course you would need to have the exact program name string in order to find it.

This topic is 15 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked