tc44
tc44

Reputation: 184

Using C# How to detect if Windows Installer 4.5 is Installed

I am trying to figure out the most efficient way to determine if Windows Installer 4.5 is installed on a machine.

I have a 2.0 application (cannot convert at this time to 3.5) and we are upgrading from MSDE to SQL 2008 Express. One of the requirements of 2008 Express is that Windows Installer 4.5 is installed on the machine. This application is deployed globally to machines both on and off of an internal network.

I would prefer to run a batch file or C# code to determine the installer version.

Please let me know your recommended methods and provide some code (or links to code).

Thanks!

Upvotes: 7

Views: 3126

Answers (3)

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

You can read the file version of the msi.dll library in the system directory:

using System.Diagnostics;
using System.IO;

public bool IsWindowsInstaller45Installed()
{
    FileVersionInfo info;
    string fileName = Path.Combine(Environment.SystemDirectory, "msi.dll");
    try {
        info = FileVersionInfo.GetVersionInfo(fileName);
    } catch (FileNotFoundException) {
        return false;
    }

    return (info.FileMajorPart > 4
            || info.FileMajorPart == 4 && info.FileMinorPart >= 5);
}

Upvotes: 10

Christopher Painter
Christopher Painter

Reputation: 55571

Like Ho1 said, you can go by the version of MSI.dll in System32 but you don't need to P/Invoke you can use the FileVersionInfo class found in System.Diagnostics.

Upvotes: 1

Hans Olsson
Hans Olsson

Reputation: 54999

Check the version of the MSI.DLL file that's in your System32 directory.

You should be able to use GetFileVersionInfo or GetFileVersionInfoEx to get out the version number.

This MSDN article has some sample code: Unsafe Code Tutorial

Upvotes: 1

Related Questions