gpt4 book ai didi

c - 如何在不安装 msi 的情况下从 msi 文件获取产品版本?

转载 作者:行者123 更新时间:2023-11-30 20:51:39 32 4
gpt4 key购买 nike

我正在寻找一个 C API,它可以获取 msi 路径并返回产品版本(主要版本和次要版本),而无需安装 API。

谢谢,埃坦

最佳答案

我不会使用开放包 - 这是一个静态数据库,因此 MsiOpenDatabase 和 SQL 是最佳选择。缺少一些包含内容,但效果很好:

#include "stdafx.h"
UINT GetProperty (MSIHANDLE dbHand, LPCTSTR propname, LPTSTR strVal)
{
PMSIHANDLE viewH = NULL;
WCHAR qry [100] = {0};
StringCchCat (qry, 100, L"Select `Value` from `Property` where `Property`='" );
StringCchCat (qry, 100, propname);
StringCchCat (qry, 100, L"'");
UINT res = MsiDatabaseOpenView (dbHand, qry, &viewH);
if (ERROR_SUCCESS!=res)
return res;
res = MsiViewExecute (viewH, 0);
if (ERROR_SUCCESS!=res)
{
MsiCloseHandle (viewH);
return res;
}
PMSIHANDLE recH=NULL;
res = MsiViewFetch (viewH, &recH);
if (ERROR_SUCCESS!=res)
{
MsiCloseHandle (viewH);
return res;
}
WCHAR buff [50] = {0};
DWORD dwlen = 50;
res = MsiRecordGetString (recH, 1, buff, &dwlen);
if (ERROR_SUCCESS!=res)
{
MsiCloseHandle (viewH);
MsiCloseHandle (recH);
return res;
}
StringCchCopy (strVal, dwlen+1, buff);
MsiViewClose (viewH);
MsiCloseHandle (recH);
return (ERROR_SUCCESS);

}

int _tmain(int argc, _TCHAR* argv[])
{
PMSIHANDLE dbH=NULL;
UINT res = MsiOpenDatabase (L"C:\\Phil\\MyDD\\Samples Setup\\GetMsiProperty\\Set2.msi", MSIDBOPEN_READONLY, &dbH);
WCHAR pversion [512] = {0};
res = GetProperty (dbH, L"ProductVersion", pversion);
WCHAR ubuff [50] = {0};
res = GetProperty(dbH, L"UpgradeCode", ubuff);
WCHAR pbuff [50] = {0};
res = GetProperty(dbH, L"ProductCode", pbuff);
WCHAR prodName [512] = {0};
res = GetProperty (dbH, L"ProductName", prodName);
WCHAR prodLang [512] = {0};
res = GetProperty (dbH, L"ProductLanguage", prodLang);
return 0;
}

关于c - 如何在不安装 msi 的情况下从 msi 文件获取产品版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27634407/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com