我有一个相当标准的inno安装程序。卸载运行时,需要重新启动,它将删除服务并注销dll。我有一些代码可以检测旧版本的软件(感谢stackoverflow)。如果检测到旧版本,并且用户希望安装新版本:
调用卸载程序
软件已卸载
系统(正确)重新启动
系统启动,我重新登录
现在应该发生的事情(imho)是安装程序应该继续它停止的地方,即安装新版本到与旧版本相同的文件夹中。但没有,什么都没发生。我已经阅读了帮助文件,检查了开关(尽我所能),并询问了谷歌博士,但什么也没有。
我的问题:是否可以这样做,即重新启动后继续安装,如果可以,如何安装?
以下是我的(很多stackoverflow)代码,除了在系统重新启动时不会继续运行(如果需要安装程序的其他部分,请告诉我):

function InitializeSetup(): Boolean;
var
  oldVersion: String;
  uninstaller: String;
  ErrorCode: Integer;
begin

  if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1') then
  begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1', 'DisplayVersion', oldVersion);
    if (CompareVersion(oldVersion, '{#MyAppVersion}') < 0) then
    begin
      if MsgBox('Version ' + oldVersion + ' of EMPSecure 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\{#MyAppID}_is1', 'UninstallString', uninstaller);
          ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
          if (ErrorCode <> 0) then
          begin
            MsgBox( 'Failed to uninstall EMPSecure version ' + oldVersion + '. Please restart Windows and run setup again.', mbError, MB_OK );
            Result := False;
          end
          else
          begin
            Result := True;
          end;
      end;
    end
    else
    begin
      MsgBox('Version ' + oldVersion + ' of EMPsecure is already installed. This installer will exit.', mbInformation, MB_OK);
      Result := False;
    end;
  end
  else
  begin
    Result := True;
  end;
end;

最佳答案

当从安装程序调用的卸载程序重新启动系统时,安装程序将永久中止。
如果要在重新启动后继续安装程序,则必须亲自处理。
例如,您可以将安装程序本身添加到RunOnce

RegWriteStringValue(
  HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\RunOnce',
  'ResumeMyInstaller', ExpandConstant('{srcexe}'));

10-07 19:10
查看更多