簡體   English   中英

使用C#如何檢測Windows Installer 4.5是否已安裝

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

我試圖找出確定Windows Installer 4.5是否安裝在計算機上的最有效方法。

我有一個2.0應用程序(此時無法轉換為3.5),我們正在從MSDE升級到SQL 2008 Express。 2008 Express的要求之一是在計算機上安裝了Windows Installer 4.5。 此應用程序全局部署到內部網絡內外的計算機上。

我更喜歡運行批處理文件或C#代碼來確定安裝程序版本。

請讓我知道您推薦的方法,並提供一些代碼(或代碼鏈接)。

謝謝!

您可以在系統目錄中讀取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);
}

檢查System32目錄中的MSI.DLL文件的版本。

您應該能夠使用GetFileVersionInfoGetFileVersionInfoEx來獲取版本號。

這篇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