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

发布于 2024-10-07 01:23:38 字数 283 浏览 0 评论 0原文

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

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

我更愿意运行批处理文件或 C# 代码来确定安装程序版本。

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦途 2024-10-14 01:23:38

您可以在系统目录中读取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);
}

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);
}
天邊彩虹 2024-10-14 01:23:38

检查 System32 目录中的 MSI.DLL 文件的版本。

您应该能够使用 GetFileVersionInfoGetFileVersionInfoEx 获取版本数字。

此 MSDN 文章有一些示例代码: 不安全代码教程

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

寄居人 2024-10-14 01:23:38

就像Ho1所说,您可以通过System32中的MSI.dll版本,但不需要P/Invoke,您可以使用System.Diagnostics中找到的FileVersionInfo类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文