INNO:检测程序是否已经安装,是则弹出卸载提示。

时间:2023-03-10 00:40:36
INNO:检测程序是否已经安装,是则弹出卸载提示。

INNO:检测程序是否已经安装,是则弹出卸载提示。

作者:少轻狂 | 发布:2010-08-05 | 更新:2013-09-05 | 分类:部署 | Disposition | 热度:2816 ℃

INNO:检测程序是否已经安装,是则弹出卸载提示。
实现原理:
探测注册表HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall(即“添加/删除程序”)中的卸载项目,若检测到则启动卸载确认对话框。
在实际应用的时候,各位需要将上面代码中“{86D79F54-E485-4011-83FE-FFC558F3DB86}”修改成自己脚本中的AppId。
基本:检测程序是否已经安装
用Inno Setup打包时,我们有时想要这样的功能:安装程序自动检测是否已经安装过,是则弹出卸载提示,否则正常安装。以下是代码片段:
01 function InitializeSetup():boolean;
02 var
03   MykeynotExist:boolean;
04   ResultCode: Integer;
05   uicmd: String;
06 begin
07   MykeynotExist:= true;
08   if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{86D79F54-E485-4011-83FE-FFC558F3DB86}_is1', 'UninstallString', uicmd) then
09   begin
10   MyKeynotExist:= false;
11   Exec(RemoveQuotes(uicmd), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
12   end;
13   Result:= MykeynotExist
14 end;
扩展:两次检测系统是否已经安装目标程序
先检测系统是否已安装官方的程序,若已安装则弹出一个消息框,当点击“确定”后自动启动官方程序卸载功能。若检测不到官方的程序,则再检测是否已经已经安 装了本程序,若已经安装,则直接启动卸载程序,若检测不到则程序开始安装。这样做的目的是防止在未卸载官方的程序的情况安装本程序,防止软件冲突。
01 function InitializeSetup():boolean;
02 var
03   MykeynotExist:boolean;
04   ResultCode: Integer;
05   uicmd: String;
06 begin
07   MykeynotExist:= true;
08   if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B7F653CF-1BE5-4F40-BA4A-E3BBC6869116}', 'UninstallString', uicmd) then
09   begin
10   MyKeynotExist:= false;
11   MsgBox('安装程序检测到您的系统中已经安装了官方的 {#AppName} '#10#10'你最好先卸载此 {#AppName} 再安装本 {#AppName}',mbInformation,MB_OK)
12   Exec(ExpandConstant('{pf}\InstallShield Installation Information\{{B7F653CF-1BE5-4F40-BA4A-E3BBC6869116}\Setup.exe'), '', '', SW_Show, ewNoWait, ResultCode);
13   end;
14   Result:= MykeynotExist
15   if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{49D79F54-D485-4011-83FE-FFC938F3DB86}_is1', 'UninstallString', uicmd) then
16   begin
17   MyKeynotExist:= false;
18   Exec(RemoveQuotes(uicmd), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
19   end;
20   Result:= MykeynotExist
21 end;