Sign in to follow this  
Followers 0
bluebearr

Detect whether an MSI has been installed

5 posts in this topic

This was a happy little discovery. There are places in the registry you can search to see if a program is installed, but they can be uncertain if the installation has been damaged. As far as I can determine, this is the "official" way to query Windows Installer to see if a product is installed. You have to know the product GUID in order to use this.

; http://windowssdk.msdn.microsoft.com/en-us/library/ms707471.aspx
; INSTALLSTATE_ABSENT   The product is installed for a different user.
; INSTALLSTATE_ADVERTISED   The product is advertised but not installed.
; INSTALLSTATE_DEFAULT  The product is installed for the current user.
; INSTALLSTATE_INVALIDARG   An invalid parameter was passed to the function.
; INSTALLSTATE_UNKNOWN  The product is neither advertised or installed.

Const $INSTALLSTATE_ABSENT = 2, $INSTALLSTATE_ADVERTISED = 1
Const $INSTALLSTATE_DEFAULT = 5, $INSTALLSTATE_INVALIDARG = -2
Const $INSTALLSTATE_UNKNOWN = -1

$prodName = "Microsoft Office XP Professional"
$prodCode = "{90110409-6000-11D3-8CFE-0050048383C9}"
$IsInstalled = DllCall("msi.dll", "int", "MsiQueryProductStateA", "str", $prodCode)
;MsgBox(0, "Return", "Return Code : " & $IsInstalled[0])
Select
    Case $IsInstalled[0] = $INSTALLSTATE_ABSENT
        $msg = " is installed for a different user."
    Case $IsInstalled[0] = $INSTALLSTATE_ADVERTISED
        $msg = " is advertised."
    Case $IsInstalled[0] = $INSTALLSTATE_UNKNOWN
        $msg = " is not installed."
    Case $IsInstalled[0] = $INSTALLSTATE_DEFAULT
        $msg = " is installed."
    Case Else
        $msg = ": The program's install state could not be determined."
EndSelect
MsgBox(0, "Install Test", $prodName & $msg)

Other keywords: msiexec


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

pretty cool.. :P

Edited by WTS

Share this post


Link to post
Share on other sites

Easiest way to find the GUID (prodcode) is to go to a system where you know the software is installed, open the registry to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, and search for the name of the software. You'll find the name in a subkey called DisplayName, and the GUID will be the key that contains this value, like so:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90110409-6000-11D3-8CFE-0050048383C9}]
"DisplayName"="Microsoft Office XP Professional"

BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

Ok what about checking the version? and maybe writing to a text file rather than to screen?

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
Sign in to follow this  
Followers 0