使用C#如何检测Windows Installer 4.5是否已安装

tc4*_*c44 7 .net c# windows installer

我试图找出确定Windows Installer 4.5是否安装在计算机上的最有效方法.

我有一个2.0应用程序(此时无法转换为3.5),我们正在从MSDE升级到SQL 2008 Express.2008 Express的要求之一是在计算机上安装了Windows Installer 4.5.此应用程序全局部署到内部网络内外的计算机上.

我更喜欢运行批处理文件或C#代码来确定安装程序版本.

请让我知道您推荐的方法,并提供一些代码(或代码链接).

谢谢!

Fré*_*idi 10

您可以msi.dll在系统目录中读取库的文件版本:

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);
}
Run Code Online (Sandbox Code Playgroud)