Inno Setup-如果机器上已经安装了应用程序,如何在安装过程中显示通知消息? [英] Inno Setup - How to display notifying message while installing if application is already installed on the machine?

查看:100
本文介绍了Inno Setup-如果机器上已经安装了应用程序,如何在安装过程中显示通知消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to Inno Setup. I am creating an installer for my C# application using Inno Setup compiler-5.1.6.

使用我的脚本创建一个安装程序,它可以正常运行.它可以安装该应用程序,也可以从控制面板中将其卸载.

Using my script an installer is created, and it works fine. It installs the application and can be uninstalled from control panel as well.

但是我的问题是,如果我的应用程序已经安装在我的计算机上,然后我尝试再次安装它,那么它将被安装而没有任何消息.它取代了较早的安装.

But my problem is that, if my application is already installed on my machine and I try to install it again it get installed without any message. It replaces the older installation.

所以我的要求是,如果已经安装了应用程序,则应该向我显示一条消息,"应用程序已安装{现有版本}.您要替换现有安装." 带有是" "和否"按钮.如果用户单击是"按钮,安装程序应正常进行,否则应退出安装向导,而不进行新安装.

So my requirement is that , if application is already installed , it should show me a message that "App already installed {existing version}. Do you want to replace existing installation." with 'Yes' and 'No' buttons. If user clicks 'Yes' button installer should proceed normally otherwise it should exit installation wizard without new installation.

AppVersion:随着版本的增加,它可以更改.

AppVersion: it is changeable as version increases.

AppId:对于所有版本,该名称都将保持不变.

AppId: it will remain same for all version.

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

So, please can someone help me to achieve above.. Thanks in advance . .

推荐答案

请参阅我的问题

Plz refer my question how to terminate installer if unstallation of legacy version of software is cancelled before executing it? , You can use same trick of checking registry for your app to check whether it is installed or not.

并检查应用程序的版本,您可以使用我从

and to check version of app you can use following code that i got from 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;

这篇关于Inno Setup-如果机器上已经安装了应用程序,如何在安装过程中显示通知消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆