Advertisement
TLama

Untitled

Oct 10th, 2014
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.22 KB | None | 0 0
  1. function IsMyClickOnceAppInstalled: Boolean;
  2. begin
  3.   Result := RegKeyExists(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Uninstall\myapp');
  4. end;
  5.  
  6. procedure UninstallMyClickOnceApp;
  7. var
  8.   ErrorCode: Integer;
  9. begin
  10.   // knowing if the rundll32.exe failed to run is quite pointless here, so I've omitted
  11.   // a return value here (ErrorCode will be always 0)
  12.   ShellExec('runas', 'rundll32.exe', 'dfshim.dll,ShArpMaintain...', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
  13. end;
  14.  
  15. function InitializeSetup: Boolean;
  16. begin                                  
  17.   Result := True;
  18.  
  19.   // check if the app. is installed before uninstalling
  20.   if IsMyClickOnceAppInstalled then
  21.   begin
  22.     // the app is installed, run the uninstaller
  23.     UninstallMyClickOnceApp;
  24.     // check once again if the app. is installed; if the user cancelled the uninstaller or
  25.     // something went wrong (which you won't be able to determine), exit the setup
  26.     if IsMyClickOnceAppInstalled then
  27.     begin
  28.       Result := False;
  29.       MsgBox('Ok, you don''t want to uninstall the previous version or you were not lucky ' +
  30.         'enough and the uninstallation failed. Setup will now exit.', mbInformation, MB_OK);
  31.     end;
  32.   end;
  33. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement