Solved

A script to check if a specific program is installed

Posted on 2008-10-15
5
1,544 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now