用inno Setup做應用程式安裝包的示例指令碼(.iss檔案)
阿新 • • 發佈:2019-02-20
{程式安裝前判斷主程式是否在執行}
function InitializeSetup(): Boolean;
var
ResultCode: Integer;
begin
if RegGetSubkeyNames(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',Guid_names) then
begin
for I:=0 to GetArrayLength(Guid_names)-1 do
begin
S := Guid_names[i];
//登錄檔中找到了此鍵
if AppName = Guid_names[i] then
begin
bool := RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S,'UninstallString',ResultStr);
//ResultStr := RemoveQuotes(ResultStr);
if bool then
begin
if MsgBox('安裝程式檢測到當前計算機已經安裝了AIS_Server。' #13#13 '您是否要解除安裝AIS_Server?', mbConfirmation, MB_YESNO) = IDYES then
// ShellExec('', ExpandConstant('{app}\unins000.exe'), '','', SW_SHOW, ewNoWait, ResultCode);
begin
Exec(RemoveQuotes(ResultStr), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
Result := false;
end
end
break;
end
else
//zdx 5.8 判斷是否已經打開了一個安裝程式
begin
if FindWindowbyWindowName('安裝 - AIS_Server')<>0 then
begin
MsgBox('安裝程式檢測到有另外一個安裝程式已經在運行了', mbConfirmation, MB_OK);
Result := false;
break;
end
end
end;
if I = GetArrayLength(Guid_names) then
Result := true;
end
else
Result := true;
end;
function InitializeSetup(): Boolean;
var
ResultCode: Integer;
begin
if RegGetSubkeyNames(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',Guid_names) then
begin
for I:=0 to GetArrayLength(Guid_names)-1 do
begin
S := Guid_names[i];
//登錄檔中找到了此鍵
if AppName = Guid_names[i] then
begin
bool := RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'+S,'UninstallString',ResultStr);
//ResultStr := RemoveQuotes(ResultStr);
if bool then
begin
if MsgBox('安裝程式檢測到當前計算機已經安裝了AIS_Server。' #13#13 '您是否要解除安裝AIS_Server?', mbConfirmation, MB_YESNO) = IDYES then
// ShellExec('', ExpandConstant('{app}\unins000.exe'), '','', SW_SHOW, ewNoWait, ResultCode);
begin
Exec(RemoveQuotes(ResultStr), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
Result := false;
end
end
break;
end
else
//zdx 5.8 判斷是否已經打開了一個安裝程式
begin
if FindWindowbyWindowName('安裝 - AIS_Server')<>0 then
begin
MsgBox('安裝程式檢測到有另外一個安裝程式已經在運行了', mbConfirmation, MB_OK);
Result := false;
break;
end
end
end;
if I = GetArrayLength(Guid_names) then
Result := true;
end
else
Result := true;
end;