esullivan

Search installed programs

5 posts in this topic

I found this to search for an installed program:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#Include <String.au3>
#include <INet.au3>
#include <Array.au3>
#include <File.au3>


If IsInstalled("Adobe Flash Player 19 NPAPI") == 1 Then
    msgbox("","", "Installed")
Else
    msgbox("","", "Not installed")
EndIf


Func IsInstalled($progName)
    Local $InstallPrograms = GetList()

    If $InstallPrograms == -1 Then Return -1 ; Cannot get list

    For $program in $InstallPrograms
        if StringLower($program.Caption) == StringLower($progName) Then
            ConsoleWrite($program.Caption & " : " & $progName & @CRLF)
            Return 1;
        EndIf
    Next
    Return -2 ; Didn't find program.
EndFunc

Func GetList()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output &= "Computer: " & $strComputer  & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        Return $colItems
    EndIf
    Return -1
EndFunc

And it works, however you have to have the exact name of the program, for example "Adobe Flash Player 19 NPAPI".  I'd like to be able to search for just "Flash".  Anyone able to modify this for that?

 

Or have a better way?

Share this post


Link to post
Share on other sites



stringinstr is your friend.

Saludos

Share this post


Link to post
Share on other sites
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#Include <String.au3>
#include <INet.au3>
#include <Array.au3>
#include <File.au3>


If IsInstalled("Flash") == 1 Then
    msgbox("","", "Installed")
Else
    msgbox("","", "Not installed")
EndIf


Func IsInstalled($progName)
    Local $InstallPrograms = GetList()

    If $InstallPrograms == -1 Then Return -1 ; Cannot get list

    For $program in $InstallPrograms
        if StringInStr(StringLower($program.Caption),StringLower($progName))  Then
            ConsoleWrite($program.Caption & " : " & $progName & @CRLF)
            Return 1;
        EndIf
    Next
    Return -2 ; Didn't find program.
EndFunc

Func GetList()
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output &= "Computer: " & $strComputer  & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        Return $colItems
    EndIf
    Return -1
EndFunc

Saludos

1 person likes this

Share this post


Link to post
Share on other sites

Thanks Dany!

Share this post


Link to post
Share on other sites

Also, if the functions are not part of a larger script where you need them, there is a lot of fluff. You could easily trim it down to something like this and save yourself 30 lines:

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20

$Program = "Flash"
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $app In $colItems
            If StringInStr(StringLower($app.Caption),StringLower($Program)) Then
                ConsoleWrite($app.Caption & " : " & $app & @CRLF)
            EndIf
        Next
    EndIf

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now