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