2
我要实现类似Inno setup - skip installation if other program is not installedInno Setup的:根据产品代码
的东西,但是我确实有MSIEXEC产品代码(如D3AA40C4-9BFB-4640-88CE-EDC93A3703CC)检测安装。那么如何根据这个产品代码来检测是否安装了另一个程序?
我要实现类似Inno setup - skip installation if other program is not installedInno Setup的:根据产品代码
的东西,但是我确实有MSIEXEC产品代码(如D3AA40C4-9BFB-4640-88CE-EDC93A3703CC)检测安装。那么如何根据这个产品代码来检测是否安装了另一个程序?
这里有MsiQueryProductState
函数。下面是它的进口与您的任务助手功能:
[Code]
#IFDEF UNICODE
#DEFINE AW "W"
#ELSE
#DEFINE AW "A"
#ENDIF
type
INSTALLSTATE = Longint;
const
INSTALLSTATE_DEFAULT = 5;
function MsiQueryProductState(szProduct: string): INSTALLSTATE;
external 'MsiQueryProductState{#AW}@msi.dll stdcall';
function IsProductInstalled(const ProductID: string): Boolean;
begin
Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;
及其可能的用途:
if IsProductInstalled('{D3AA40C4-9BFB-4640-88CE-EDC93A3703CC}') then
MsgBox('The product is installed.', mbInformation, MB_OK);
感谢。 INSTALLSTATE_DEFAULT未知,所以简单地使用'5':MsiQueryProductState(ProductID)= 5; //来自msi.h' – RobertK
不客气!但不,不要这样做。不要使用魔法常量。有一天,你或其他人会来你的脚本,并会想知道那是什么5.对不起,这是我的['复制粘贴失败](http://stackoverflow.com/a/11172939/960757)。 – TLama
就像别人有同样的问题:我总是从MsiQueryProductState得到-2(INSTALLSTATE_INVALIDARG)作为返回值。为呼叫添加'{}'很重要,所以'IsProductInstalled('{696C9E52-ADB6-42C8-B6E3-026EF21D369A}')' – RobertK