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
Check for an installed program
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.
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.
- harry.butts
- Posts: 13
- Last visit: Thu Aug 28, 2008 6:58 pm
Check for an installed program
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
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
- harry.butts
- Posts: 13
- Last visit: Thu Aug 28, 2008 6:58 pm
Check for an installed program
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?
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?
Check for an installed program
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".
Of course you would need to have the exact program name string in order to find it.
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.