【问题标题】:Inno Setup - How to display notifying message while installing if application is already installed on the machine?Inno Setup - 如果应用程序已安装在机器上,如何在安装时显示通知消息?
【发布时间】:2014-10-13 06:06:02
【问题描述】:

我是 Inno Setup 的新手。我正在使用 Inno Setup compiler-5.1.6 为我的 C# 应用程序创建安装程序。

使用我的脚本创建了一个安装程序,它工作正常。它安装应用程序,也可以从控制面板卸载。

但我的问题是,如果我的应用程序已经安装在我的机器上,并且我尝试再次安装它,它会在没有任何消息的情况下安装。它取代了旧的安装。

所以我的要求是,如果应用程序已经安装,它应该向我显示一条消息 “应用程序已经安装 {existing version}。你想替换现有安装。” 与“是” '和'否'按钮。如果用户单击“是”按钮,安装程序应正常进行,否则应退出安装向导,无需重新安装。

AppVersion:随着版本的增加而变化。

AppId:所有版本都将保持相同。

所以,请有人帮我实现上述目标.. 提前致谢 。 .

【问题讨论】:

  • 如果我是你,如果用户尝试安装旧版本,我也会警告他们,而不仅仅是版本匹配...

标签: installation inno-setup


【解决方案1】:

请参考我的问题how to terminate installer if unstallation of legacy version of software is cancelled before executing it?,您可以使用相同的技巧检查注册表检查您的应用是否已安装。

要检查应用程序的版本,您可以使用我从https://blog.lextudio.com/2007/08/inno-setup-script-sample-for-version-comparison-2/ 获得的以下代码:

[Code]

function GetNumber(var temp: String): Integer;
var
  part: String;
  pos1: Integer;
begin
  if Length(temp) = 0 then
  begin
    Result := -1;
    Exit;
  end;
    pos1 := Pos('.', temp);
    if (pos1 = 0) then
    begin
      Result := StrToInt(temp);
    temp := '';
    end
    else
    begin
    part := Copy(temp, 1, pos1 - 1);
      temp := Copy(temp, pos1 + 1, Length(temp));
      Result := StrToInt(part);
    end;
end;

function CompareInner(var temp1, temp2: String): Integer;
var
  num1, num2: Integer;
begin
    num1 := GetNumber(temp1);
  num2 := GetNumber(temp2);
  if (num1 = -1) or (num2 = -1) then
  begin
    Result := 0;
    Exit;
  end;
      if (num1 > num2) then
      begin
        Result := 1;
      end
      else if (num1 < num2) then
      begin
        Result := -1;
      end
      else
      begin
        Result := CompareInner(temp1, temp2);
      end;
end;

function CompareVersion(str1, str2: String): Integer;
var
  temp1, temp2: String;
begin
    temp1 := str1;
    temp2 := str2;
    Result := CompareInner(temp1, temp2);
end;

function InitializeSetup(): Boolean;
var
  oldVersion: String;
  uninstaller: String;
  ErrorCode: Integer;
begin
  if RegKeyExists(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1') then
  begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1','DisplayVersion', oldVersion);
    if (CompareVersion(oldVersion, '6.0.0.1004') < 0) then
    begin
      if MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. Continue to use this old version?',mbConfirmation, MB_YESNO) = IDYES then
      begin
        Result := False;
      end
      else
      begin
          RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F768F6BA-F164-4599-BC26-DCCFC2F76855}_is1','UninstallString', uninstaller);
          ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
          Result := True;
      end;
    end
    else
    begin
      MsgBox('Version ' + oldVersion + ' of Code Beautifier Collection is already installed. This installer will exit.',mbInformation, MB_OK);
      Result := False;
    end;
  end
  else
  begin
    Result := True;
  end;
end;

【讨论】:

  • 一件重要的事情,您应该始终检查RegQuery...ShellExec 函数的返回值。我知道您假设如果存在卸载注册表项,则 DisplayVersionUninstallString 键将在那里。但如果他们失踪了怎么办?此处使用的版本比较函数将告诉您,如果您传递一个空字符串,则版本等于(如果缺少 reg. 值,这就是您在 oldVersion 变量中得到的内容)。最后一件事是卸载密钥可以存储在HKEY_CURRENT_USER 根目录下。 &lt;/nitpick&gt; :)
【解决方案2】:

GetNumber 函数仅返回“主要”版本。 要应用完整版本比较,您必须连接主要和次要版本部分。

function GetNumber(var temp: String): Integer;
var
  part: String;
  pos1: Integer;
begin
  if Length(temp) = 0 then
  begin
    Result := -1;
    Exit;
  end;
    pos1 := Pos('.', temp);
    if (pos1 = 0) then
    begin
      Result := StrToInt(temp);
      temp := '';
    end
    else
    begin
    part := Copy(temp, 1, pos1 - 1);
      temp := Copy(temp, pos1 + 1, Length(temp));
      insert(temp, part, pos1);
      Result := StrToInt(part);
    end;
end;

【讨论】:

    猜你喜欢
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    相关资源
    最近更新 更多