Solved

A script to check if a specific program is installed

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

919 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

13 Experts available now in Live!

Get 1:1 Help Now