Solved

A script to check if a specific program is installed

Posted on 2008-10-15
5
1,546 Views
Last Modified: 2010-05-18
Hi,

I have a script (from Rob Sampson) that checks for all installed programs in Add/Remove programs. I would like to have a script that checks for just on specific program (in this case Update for Windows XP (KB943729)). I have tried numerous powershell and VB scripts, but none were indicating the presence of the KB, except for Rob's script, which outputs all installed apps to an excel file.

It's the script at the bottom here:
http://www.experts-exchange.com/Programming/Languages/Q_23619694.html?sfQueryTermInfo=1+applic+check+instal+rob+script

Any help on this would be appreciated.
0
Comment
Question by:sherryfitzgroup
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22725631
Hi, I have taken the relevant registry searching part out of my code for you to use here.

You should only need to change:
strComputer = "."
strAppToFind = "KB943729"

to suit.

Regards,

Rob.
Const HKEY_LOCAL_MACHINE = &H80000002
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strComputer = "."
strAppToFind = "KB943729"
Set objRegistry = GetObject("winmgmts:"   & _
	"{impersonationLevel=Impersonate}!\\" & _
	strComputer & "\root\default:StdRegProv")
 
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
 
strFoundApp = ""
On Error Resume Next
For Each strSubKey In arrSubKeys
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayName", strDisplayName
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
	objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "InstallLocation", strInstallLocation
	
	If InStr(LCase(strDisplayName), LCase(strAppToFind)) > 0 Then strFoundApp = strDisplayName
	
	strDisplayName = vbEmpty
	strDisplayVersion = vbEmpty
	strInstallLocation = vbEmpty
Next
 
If strFoundApp = "" Then
	MsgBox "Could not find " & strAppToFind & " on " & strComputer
Else
	MsgBox "Found" & VbCrLf & strFoundApp & VbCrLf & "on " & strComputer
End If

Open in new window

0
 
LVL 2

Author Comment

by:sherryfitzgroup
ID: 22726228
Thanks for the quick reply Rob. It correctly detected the KB on my PC. How would I get it to check all computers in a txt file?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 22726477
Try this.....it will now take input from a "Computers.txt" text file, ping those computers, read their registry, and output the results of the search to a CSV file.

Regards,

Rob.
strInputFile = "Computers.txt"
strOutputFile = "Results.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
strAppToFind = "KB943729"
 
strResults = """Computer"",""Searched For"",""Found"""
Set objFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objFile.AtEndOfStream
	strComputer = objFile.ReadLine
	If Ping(strComputer) = True Then
		On Error Resume Next
		Set objRegistry = GetObject("winmgmts:"   & _
			"{impersonationLevel=Impersonate}!\\" & _
			strComputer & "\root\default:StdRegProv")
		
		If Err.Number = 0 Then
			On Error GoTo 0
			objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
			 
			strFoundApp = ""
			On Error Resume Next
			For Each strSubKey In arrSubKeys
				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayName", strDisplayName
				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "InstallLocation", strInstallLocation
				
				If InStr(LCase(strDisplayName), LCase(strAppToFind)) > 0 Then strFoundApp = strDisplayName
				
				strDisplayName = vbEmpty
				strDisplayVersion = vbEmpty
				strInstallLocation = vbEmpty
			Next
			
			'If strFoundApp = "" Then
			'	MsgBox "Could not find " & strAppToFind & " on " & strComputer
			'Else
			'	MsgBox "Found" & VbCrLf & strFoundApp & VbCrLf & "on " & strComputer
			'End If
			strResults = strResults & VbCrLf & """" & strComputer & """,""" & strAppToFind & """,""" & strFoundApp & """"
		Else
			Err.Clear
			On Error GoTo 0
			strResults = strResults & VbCrLf & """" & strComputer & """,""" & strAppToFind & """,""FAILED TO CONNECT"""
		End If
	Else
		strResults = strResults & VbCrLf & """" & strComputer & """,""" & strAppToFind & """,""FAILED TO PING"""
	End If
Wend
objFile.Close
Set objFile = Nothing
 
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
 
MsgBox "Done. Please see " & strOutputFile
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
LVL 2

Author Closing Comment

by:sherryfitzgroup
ID: 31506491
A1 Rob, you the man.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22726786
Thanks for the grade.

Regards,

Rob.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question