2015-06-17 66 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