Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i check if a particular MSI is installed?

Tags:

powershell

I'm writing a powershell script that will install some dependencies for my webapp. In my script, I'm running into a recurring problem of checking if a particular application is installed. it seems there's a unique way of checking if an application exists for each application (ie: by checking the existing of this folder or this file on c:). Is there not a way that i can check if an application is installed by querying a list of installed applications?

like image 796
burnt1ce Avatar asked Jan 20 '11 21:01

burnt1ce


People also ask

How do I find MSI installation options?

The Windows Installer MSI options can be found by opening a command window (click the Windows Start button, type in cmd and press ENTER on the keyboard), and in the command window typing msiexec /? and pressing ENTER on the keyboard.

How do I search for MSI files?

To see useful names of msi files in C:\Windows\Installer right click at the top of explorer and add the field to view Subject (will probably have to select more as it isn't a default like name, date modified, etc.) From here you can find the msi and use it to uninstall programs. Save this answer.

How do I find my MSI product name?

If you have access to the MSI, then probably the easiest way to find the ProductCode is by opening an MSI editor tool and heading to the Property table. There, you will find the ProductCode property, which gives you the unique identifier of that Windows Installer package.


2 Answers

Here is the code I use sometimes (not too often, so...). See the help comments for details.

<#
.SYNOPSIS
    Gets uninstall records from the registry.

.DESCRIPTION
    This function returns information similar to the "Add or remove programs"
    Windows tool. The function normally works much faster and gets some more
    information.

    Another way to get installed products is: Get-WmiObject Win32_Product. But
    this command is usually slow and it returns only products installed by
    Windows Installer.

    x64 notes. 32 bit process: this function does not get installed 64 bit
    products. 64 bit process: this function gets both 32 and 64 bit products.
#>
function Get-Uninstall
{
    # paths: x86 and x64 registry keys are different
    if ([IntPtr]::Size -eq 4) {
        $path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    }
    else {
        $path = @(
            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        )
    }

    # get all data
    Get-ItemProperty $path |
    # use only with name and unistall information
    .{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} |
    # select more or less common subset of properties
    Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, HelpLink, UninstallString |
    # and finally sort by name
    Sort-Object DisplayName
}

Get-Uninstall
like image 180
Roman Kuzmin Avatar answered Oct 01 '22 13:10

Roman Kuzmin


To get a list of installed applications try:

$r = Get-WmiObject Win32_Product | Where {$_.Name -match 'Microsoft Web Deploy' }
if ($r -ne $null) { ... }

See the docs on Win32_Product for more info.

like image 36
Keith Hill Avatar answered Oct 01 '22 13:10

Keith Hill