2015-06-17 69 views

回答

2

这里有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); 
+0

感谢。 INSTALLSTATE_DEFAULT未知,所以简单地使用'5':MsiQueryProductState(ProductID)= 5; //来自msi.h' – RobertK

+1

不客气!但不,不要这样做。不要使用魔法常量。有一天,你或其他人会来你的脚本,并会想知道那是什么5.对不起,这是我的['复制粘贴失败](http://stackoverflow.com/a/11172939/960757)。 – TLama

+2

就像别人有同样的问题:我总是从MsiQueryProductState得到-2(INSTALLSTATE_INVALIDARG)作为返回值。为呼叫添加'{}'很重要,所以'IsProductInstalled('{696C9E52-ADB6-42C8-B6E3-026EF21D369A}')' – RobertK