1

我使用 innosetup 创建了一个安装程序(myinstaller)来安装应用程序(myapp)。代码片段是:

function legacy_check(): Boolean;
    begin
       ShellExec('runas', 'rundll32.exe', 'dfshim.dll,ShArpMaintain SecretsUtility.application, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=amd64', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
       Result := True; 
    end;

function InitializeSetup(): Boolean;
    begin                                  
       Result:=legacy_check(); // after this line only inno setup wizard page will appear 
       // code to install latest version 
     end;

这里的函数 legacy_check() 检查系统中是否存在旧版本的myapp并将其卸载并返回 true 。以便myinstaller可以继续进行。

但是,在卸载旧版本的过程中,它会询问用户是否卸载。那个时候如果用户按OK卸载,它工作正常。但是如果用户按取消卸载旧版本,它应该终止myinstaller。但它没有终止,因为它仍然返回True。

所以我认为当用户按下取消按钮卸载时我需要得到一些返回码,这样使用返回码我可以返回真或假。

那么当用户按下取消卸载时有什么方法可以获取返回码,以便我可以在行后使用它,

ShellExec('runas', 'rundll32.exe', 'dfshim.dll,ShArpMaintain SecretsUtility.application, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=amd64', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);  ?

否则请告诉我如何静默卸载它。我对如何在ShellExec中使用/SILENT参数感到困惑,因为已经存在参数。所以请给我一些想法。

4

1 回答 1

0

我更改了我的代码如下以满足要求:

function legacy_check(): Boolean;
begin
   ShellExec('runas', 'rundll32.exe', 'dfshim.dll,ShArpMaintain SecretsUtility.application, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=amd64', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
   if RegKeyExists(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Uninstall\myapp') then
                  Result := False
               else
                  Result := True; 
end;

function InitializeSetup(): Boolean;
begin                                  
   Result:=legacy_check();
    if Not Result then 
    begin
       Result:=False
    else
      // code to install latest version 
end;
于 2014-10-10T12:42:17.480 回答