how to terminate installer if unstallation of legacy version of software is cancelled before executing it?

…衆ロ難τιáo~ 提交于 2019-12-11 09:45:33

问题


I have created an installer(myinstaller) using innosetup to install an application (myapp). The code snippet is :

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;

Here the function legacy_check() checks for existance of old version of myapp in the system and uninstalls it and returns true . so that myinstaller can proceed further .

But, here during uninstallation of old version , it asks user whether to uninstall or not. That time if user presses OK to uninstall, it works fine .But if user presses cancel to uninstall old version ,it should terminate myinstaller.But it is not terminating Since it returns True anyway.

So i think i need to get some return code when user presses cancel button to uninstall ,so that using return code i can return either true or false .

So Is there any way to get returncode when user presses cancel to uninstall , so that i can use it after the line,

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

otherwise please tell me how to uninstall it silently . I am confused about how to use /SILENT parameter in ShellExec since there are parameters present already . So please suggest me some idea.


回答1:


I changed my code as below to achieve the requirement :

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;


来源:https://stackoverflow.com/questions/26297328/how-to-terminate-installer-if-unstallation-of-legacy-version-of-software-is-canc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!