Link to home
Start Free TrialLog in
Avatar of sherryfitzgroup
sherryfitzgroupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

A script to check if a specific program is installed

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:
https://www.experts-exchange.com/questions/23619694/Need-to-find-if-1-specific-software-is-installed-in-all-machine-names-in-the-file-and-output-the-machine-names-that-has-the-software.html?sfQueryTermInfo=1+applic+check+instal+rob+script

Any help on this would be appreciated.
Avatar of RobSampson
RobSampson
Flag of Australia image

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

Avatar of sherryfitzgroup

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A1 Rob, you the man.
Thanks for the grade.

Regards,

Rob.