从 Windows 安装项目中读取产品编号

Read Product Number from Windows Setup Project

我需要获取我使用 InstalledShield 创建 .exe 的安装项目的产品编号。

我在安装程序 API 中阅读了有关 MsiGetProductInfo() 的内容,但在示例代码 c# 中找不到任何应用程序。

谢谢。

MsiGetProductInfo 无法运行,因为安装程序是使用 Wix Bootstrapper 构建的。您可以做的是使用任何归档程序(它最终是一个归档文件)打开可执行文件并解析名为 0 的文件,这是一个 XML。您可以在那里找到所有信息,例如版本、产品名称、产品密钥等。

你指的是 MsiGetProductInfo,所以我假设你有一个 Windows 安装程序 MSI 文件,你的 exe 安装(因为它引导先决条件)并且你想在你之后获取信息'已经安装了您的设置。

这是p/invoke签名:

DllImport("msi.dll", CharSet=CharSet.Unicode)]
static extern Int32 MsiGetProductInfo(string product, 
  string property, [Out] StringBuilder valueBuf, ref Int32 len)

基本上,Product 是 MSI 的 ProductCode guid,是一个被 {} 括号包围的字符串。

您尚未发布您可能尝试过的任何代码,因此无法诊断您可能遇到的任何问题。如果 "product number" 是指版本,那么您可以使用此处记录的任何值:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370130(v=vs.85).aspx

INSTALLPROPERTY_VERSIONSTRING 之类的东西是在 Windows SDK 的 msi.h 中定义的,值为 "VersionString"。

此示例中的信息也应该足够多:

MSI Interop using MSIEnumRelatedProducts and MSIGetProductInfo

随着升级的发生,许多不同的 ProductCode 的 UpgradeCode 通常保持不变,因此如果您在 UpgradeCode 上使用 MsiEnumRelatedProducts 到 return ProductCode,然后将该 ProductCode 插入 MsiGetProductInfo,则代码不会有太大变化.