1

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.

beginner
  • 463
  • 5
  • 18
  • Oh, again that ClickOnce installer (called by rundll). How to silently uninstall a ClickOnce deployed application has been asked [`quite recently`](http://stackoverflow.com/q/26256602/960757). You are facing yet another problem, you won't be able to determine that the user cancelled the ClickOnce uninstaller because the rundll32.exe won't return anything else than 0, so there is no way to get any feedback from the executed library function. If you are able to detect whether the ClickOnce application is installed, I would do it again after your `legacy_check` function returns. – TLama Oct 10 '14 at 10:43
  • @TLama , it means i can't unstall it silently . and can't terminate my installer once user presses cancel button ? Atleast can i use cancel button event handling something like that ? – beginner Oct 10 '14 at 10:52
  • First off, Inno Setup has nothing to do with ClickOnce. Now I'm quite lost what you are actually going to do. I got your question as that you want to detect if the user pressed a cancel button of the executed ClickOnce uninstaller. Isn't that so ? – TLama Oct 10 '14 at 11:03
  • MS provides no (sensible) API for that piece of... software :) And I meant that you cannot get any feedback from your `ShellExec` function call, from that ClickOnce something. So if you are asking whether you can detect if the user pressed the cancel button in that ClickOnce uninstaller, then no, that is not possible (unless you would interface that ClickOnce uninstaller other way than calling rundll32.exe). – TLama Oct 10 '14 at 11:04
  • its not clickonce's uninstaller . It is the uninstaller string that i got from regedit after installing the setup file . – beginner Oct 10 '14 at 11:05
  • dfshim.dll is part of ClickOnce, uninstall string like `rundll32.exe dfshim.dll,ShArpMaintain...` has nothing to do with Inno Setup. Inno Setup creates uninstaller binary files, like e.g. unins000.exe. – TLama Oct 10 '14 at 11:06

1 Answers1

0

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;
beginner
  • 463
  • 5
  • 18
  • `if not Result then Result := False` doesn't do so much :) Anyway, I would rather make 2 functions, one for checking if the app is installed and one for uninstalling. That way you could easily check if the app. is installed and only then uninstall. I mean [`something like`](http://pastebin.com/vBfxP3ik). – TLama Oct 10 '14 at 13:00
  • @TLama , yes its better than my approach .. :) Thank you . Instead of comment ,Can you please write ur answer so that i can accept it as answer ? :) – beginner Oct 13 '14 at 05:40
  • Feel free to include it in your answer ;) – TLama Oct 15 '14 at 08:02
  • @TLama , yes i used it in my code , it's working fine now .Thank you :) – beginner Oct 15 '14 at 08:28