如何检测旧安装和提供删除?

Exa*_*Exa 16 inno-setup

如何检测用户是否已安装软件,如果是,如何提供删除旧版本的可能性?

我写了一些行来检查.这是正确的吗?如果这是正确的,那么我该如何让用户选择是继续安装还是卸载旧版本?

#define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\setupname_is1"

var
  uninstallPath: string;

function InitializeSetup: Boolean;
begin
  if (RegQueryStringValue(HKLM,'{#UNINSTKEY}','UninstallString',uninstallPath)) and
     (uninstallPath <> '') and (fileexists(uninstallPath)) then
  begin
    Result :=
      (MsgBox(CustomMessage('NotVerifiedVersionFound'), mbConfirmation,
              MB_YESNO or MB_DEFBUTTON2) = IDYES);
  end;
  { ... }
end;
Run Code Online (Sandbox Code Playgroud)

Rob*_*beN 21

您可以使用Craig McQueen最初发布的解决方案:InnoSetup:如何自动卸载以前安装的版本?

function GetUninstallString: string;
var
  sUnInstPath: string;
  sUnInstallString: String;
begin
  Result := '';
  sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); { Your App GUID/ID }
  sUnInstallString := '';
  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
  Result := sUnInstallString;
end;

function IsUpgrade: Boolean;
begin
  Result := (GetUninstallString() <> '');
end;

function InitializeSetup: Boolean;
var
  V: Integer;
  iResultCode: Integer;
  sUnInstallString: string;
begin
  Result := True; { in case when no previous version is found }
  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1', 'UninstallString') then  { Your App GUID/ID }
  begin
    V := MsgBox(ExpandConstant('Hey! An old version of app was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); { Custom Message if App installed }
    if V = IDYES then
    begin
      sUnInstallString := GetUninstallString();
      sUnInstallString :=  RemoveQuotes(sUnInstallString);
      Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
      Result := True; { if you want to proceed after uninstall }
      { Exit; //if you want to quit after uninstall }
    end
    else
      Result := False; { when older version present and not uninstalled }
  end;
end;
Run Code Online (Sandbox Code Playgroud)

  • +1只是几个音符.如果应用程序是由非管理员安装的(因此注册表项位于`HKCU`而不是`HKLM`),代码将不起作用.也可以使用`{#SetupSetting("AppId")}`或预处理器变量来避免在注册表键路径中重复`AppId`.有关示例,请参阅我对[Inno设置:如何在安装时覆盖但不在更改时的覆盖?](http://stackoverflow.com/q/30566752/850848)的回答.或[此代码的来源](http://stackoverflow.com/a/2099805/850848),后者也包括在内. (3认同)

归档时间:

查看次数:

25980 次

最近记录:

8 年,2 月 前