MsiOpenProduct是从已安装产品读取属性的正确方法吗? [英] Is MsiOpenProduct the correct way to read properties from an installed product?

查看:159
本文介绍了MsiOpenProduct是从已安装产品读取属性的正确方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个MSI产品代码,我想从已经安装的产品中获取升级代码(以及其他属性)。我已经通过调用MsiOpenProduct方法,然后是MsiGetProductProperty()来尝试此操作。一个(简短的)示例如下所示:

Given an MSI product code I want to get the upgrade code (among other properties) from an already installed product. I have tried this by calling the MsiOpenProduct method, followed by MsiGetProductProperty(). An (abbreviated) example looks like this:

MSIHANDLE handle = NULL;
MsiOpenProduct(strProductCode,&handle);
CString strUpgradeCode;
MsiGetProductProperty(handle,_T("UpgradeCode"), strUpgradeCode.GetBuffer(GUID_LENGTH), &dwSize);
strUpgradeCode.ReleaseBuffer();
MsiCloseHandle(handle);

这为我提供了所需的值,从MSDN文档中判断,这似乎是一种有效的方法

This gets me the desired value, and judging from the MSDN documentation this seems like a valid way to do this:


MsiOpenProduct函数打开一个
产品,与访问产品数据库的函数
一起使用。当不再需要
句柄时,必须使用该句柄将
MsiCloseHandle函数调用为

The MsiOpenProduct function opens a product for use with the functions that access the product database. The MsiCloseHandle function must be called with the handle when the handle is no longer needed.

但是,对MsiOpenProduct()的调用会弹出 Windows安装程序正在准备安装...对话框。调用MsiCloseHandle()使它再次消失。

However the call to MsiOpenProduct() pops up the "Windows installer is preparing the installation..." dialog. The call to MsiCloseHandle() makes it disappear again.

这让我感到奇怪:


  • 对MsiOpenProduct()的调用是什么在引擎盖下做?我不想触发任何动作,我只想读取属性。

  • 我不介意弹出对话框,因为这仅适用于单元测试代码,只要它没有副作用即可。而且由于有许多单元测试可以执行此操作,因此在快速连续打开和关闭句柄时它仍然必须能够工作。

  • 尽管我偶然发现了MsiGetProductInfo方法,但似乎没有办法获取升级代码。我对吗?

  • MsiOpenProduct是读取属性(如升级代码)的正确方法吗?

  • What does the call to MsiOpenProduct() do under the hood? I do not want to trigger any actions, I just want to read properties.
  • I don't mind the dialog popping up, as this is only for unit test code as long as this has no side effects. And as there are many unit tests that do this, it must still work when opening and closing handles in rapid succession.
  • Although I stumbled over the MsiGetProductInfo method, there seems to be no way to get the upgrade code. Am I right?
  • Is MsiOpenProduct the correct way to read properties like the upgrade code?

推荐答案

MsiOpenProduct应该很好,只要您不运行任何序列或动作,它就不会做任何事情。如果要使对话框静音,则可以谨慎使用MsiSetInternalUI()或MsiSetExternalUI()。

MsiOpenProduct should be fine So long as you don't run any sequences or actions, it won't do anything. If you want to silence the dialog, you can with careful use of either MsiSetInternalUI() or MsiSetExternalUI().

只要 ProductCode UpgradeCode 是安全静态的(即,只要它们不被转换更改),就是使用MsiGetProductInfo()并在其上调用MsiOpenDatabase()。区别在于MsiOpenProduct()(或类似的MsiOpenPackage)将应用安装时使用的转换并准备会话,而MsiOpenDatabase()则不执行。

Another approach you can take, as long as the ProductCode and UpgradeCode are safely static (i.e. as long as they aren't changed by transforms), is to locate the database using MsiGetProductInfo() and call MsiOpenDatabase() on that. The difference is that MsiOpenProduct() (or similarly MsiOpenPackage) applies the transforms that were used at installation time and prepares a session, whereas MsiOpenDatabase() does neither.

这篇关于MsiOpenProduct是从已安装产品读取属性的正确方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆