Inno Setup 安装前卸载原程序

Inno Setup 安装前卸载原程序

分类: Install Setup

很多時候我們需要在安裝文件之前卸載原有的程序而不是覆蓋安裝,本文的code就是實現了這樣的功能。

實現原理是:從注冊表'UninstallString'項中讀取卸載信息,用Exec進行靜默卸載。

下面code中APP_NAME為你的程序名,可以去注冊表中確認。

 1 function InitializeSetup(): boolean;
 2 var
 3 ResultStr: String;
 4 ResultCode: Integer;
 5 begin
 6 if RegQueryStringValue(HKLM, 'SOFTWAREMicrosoftWindowsCurrentVersionUninstallAPP_NAME_is1', 'UninstallString', ResultStr) then
 7 begin
 8 ResultStr := RemoveQuotes(ResultStr);
 9 Exec(ResultStr, '/silent', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
10 end;
11 result := true;
12 end;
原文地址:https://www.cnblogs.com/joean/p/4843124.html