简体   繁体   English

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

[英]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. 我试图找出确定Windows Installer 4.5是否安装在计算机上的最有效方法。

I have a 2.0 application (cannot convert at this time to 3.5) and we are upgrading from MSDE to SQL 2008 Express. 我有一个2.0应用程序(此时无法转换为3.5),我们正在从MSDE升级到SQL 2008 Express。 One of the requirements of 2008 Express is that Windows Installer 4.5 is installed on the machine. 2008 Express的要求之一是在计算机上安装了Windows Installer 4.5。 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. 我更喜欢运行批处理文件或C#代码来确定安装程序版本。

Please let me know your recommended methods and provide some code (or links to code). 请让我知道您推荐的方法,并提供一些代码(或代码链接)。

Thanks! 谢谢!

You can read the file version of the msi.dll library in the system directory: 您可以在系统目录中读取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);
}

Check the version of the MSI.DLL file that's in your System32 directory. 检查System32目录中的MSI.DLL文件的版本。

You should be able to use GetFileVersionInfo or GetFileVersionInfoEx to get out the version number. 您应该能够使用GetFileVersionInfoGetFileVersionInfoEx来获取版本号。

This MSDN article has some sample code: Unsafe Code Tutorial 这篇MSDN文章有一些示例代码: Unsafe Code Tutorial

就像Ho1说的那样,你可以使用System32中的MSI.dll版本,但是你不需要P / Invoke你可以使用System.Diagnostics中的FileVersionInfo类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM