Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A script to check if a specific program is installed

Posted on 2008-10-15
5
Medium Priority
?
1,556 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

688 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