MsiEnumProductsEx 不工作
我有以下应用程序,用于检查系统中已安装的程序:
#include <iostream>
#include <Msi.h>
#include <Windows.h>
using namespace std;
void main()
{
UINT ret;
DWORD dwIndex = 0;
DWORD dwContext = MSIINSTALLCONTEXT_ALL;
char szInstalledProductCode[39] = {0};
char szSid[128] = {0};
const char* szUserSid = "s-1-1-0";
DWORD cchSid;
MSIINSTALLCONTEXT dwInstalledContext;
do
{
memset(szInstalledProductCode, 0, sizeof(szInstalledProductCode));
cchSid = sizeof(szSid)/sizeof(szSid[0]);
ret = MsiEnumProductsEx(
NULL, // all the products in the context
szUserSid, // i.e.Everyone, all users in the system
dwContext,
dwIndex,
szInstalledProductCode,
&dwInstalledContext,
szSid,
&cchSid
);
if(ret == ERROR_SUCCESS)
{
char* name = MsiGetProductInfoEx (
szInstalledProductCode,
cchSid == 0 ? NULL : szSid,
dwInstalledContext,
INSTALLPROPERTY_INSTALLEDPRODUCTNAME
);
char* version = MsiGetProductInfoEx (
szInstalledProductCode,
cchSid == 0 ? NULL : szSid,
dwInstalledContext,
INSTALLPROPERTY_VERSIONSTRING
);
cout << name << endl;
cout << " - " << version << endl;
dwIndex++;
}
} while(ret == ERROR_SUCCESS);
}
我正在使用 Microsoft Visual C++ Express 2010。该应用程序是 MBCS。在工作室中,这四件事是红色的(错误):
MSIINSTALLCONTEXT_ALL
MSIINSTALLCONTEXT
MsiEnumProductsEx
MsiGetProductInfoEx
我链接了 Msi。 lib(项目属性 -> 链接器 -> 输入 -> 其他依赖项)。我只是想弄清楚 MsiEnumProductsEx
函数是如何工作的。我知道还有其他问题,但我只是不明白为什么它不起作用,因为我认为至少我拥有可用功能的一切。谢谢!
I have the following application, to check installed programs in a system:
#include <iostream>
#include <Msi.h>
#include <Windows.h>
using namespace std;
void main()
{
UINT ret;
DWORD dwIndex = 0;
DWORD dwContext = MSIINSTALLCONTEXT_ALL;
char szInstalledProductCode[39] = {0};
char szSid[128] = {0};
const char* szUserSid = "s-1-1-0";
DWORD cchSid;
MSIINSTALLCONTEXT dwInstalledContext;
do
{
memset(szInstalledProductCode, 0, sizeof(szInstalledProductCode));
cchSid = sizeof(szSid)/sizeof(szSid[0]);
ret = MsiEnumProductsEx(
NULL, // all the products in the context
szUserSid, // i.e.Everyone, all users in the system
dwContext,
dwIndex,
szInstalledProductCode,
&dwInstalledContext,
szSid,
&cchSid
);
if(ret == ERROR_SUCCESS)
{
char* name = MsiGetProductInfoEx (
szInstalledProductCode,
cchSid == 0 ? NULL : szSid,
dwInstalledContext,
INSTALLPROPERTY_INSTALLEDPRODUCTNAME
);
char* version = MsiGetProductInfoEx (
szInstalledProductCode,
cchSid == 0 ? NULL : szSid,
dwInstalledContext,
INSTALLPROPERTY_VERSIONSTRING
);
cout << name << endl;
cout << " - " << version << endl;
dwIndex++;
}
} while(ret == ERROR_SUCCESS);
}
I am using Microsoft Visual C++ Express 2010. The application is MBCS. In studio, these four things are in red (error):
MSIINSTALLCONTEXT_ALL
MSIINSTALLCONTEXT
MsiEnumProductsEx
MsiGetProductInfoEx
I linked the Msi.lib (Project properties -> Linker -> Input -> Additional Dependencies). I am just trying to figure out how MsiEnumProductsEx
function works. I know there are other questions around, but I just can't understand why it isn't working because I think that I have everything for the functions to be available, at least. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当 _WIN32_MSI >= 300 时,MSIINSTALLCONTEXT_ALL(及相关标识符)才会在
中定义。您必须告诉 Windows SDK 您所针对的最低操作系统版本是什么,方法是在安装任何 SDK 标头之前定义一些宏(例如
或
)。您可以根据此 MSDN 页面。
一旦您定义了合适的最低版本(例如 Windows XP SP2 及更高版本),那么 _WIN32_MSI 将被设置为适当的级别,并且您应该获得符号。
The MSIINSTALLCONTEXT_ALL (and related identifiers) are defined in
<msi.h>
only if _WIN32_MSI >= 300. You have to tell the Windows SDK what the minimum OS version you're targeting is, by defining a few macros before installing any SDK headers (like<msi.h>
or<windows.h>
).You do that according to this MSDN page.
Once you've defined a suitable minimum version (looks like Windows XP SP2 and up), then _WIN32_MSI will be set to an appropriate level, and you should get the symbols.