Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a nonempty folder in inno setup

I have created an installer using Inno Setup which contains 5 files in it. I have added an additional feature so that user can install it in custom path.

After installing, a folder will be created in selected path. Now I will copy some other files in this folder. But after un-installation the following cases are happening:

  1. let user installs it in default location, then a new folder say myfolder is created in that location, now user creates 2 new files and copies them in this folder. After un-installing there is no problem; myfolder will be deleted along with 2 new files(which are created after installing).

  2. now let user install it in custom location, then a new folder say myfolder is created in that location, now user creates 2 new files and copies them in this folder. after uninstalling myfolder is not deleting since 2 new files in it (which are created after installing).

Here is my code:

function GetInstalledLocation(): String;
var
installLocation: String;
begin
if RegKeyExists(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\   {36CBFC-6ACC-4232-90CF-E95BC473C168}_is1') then
   begin
   RegQueryStringValue(HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1536CBFC-6ACC-4232-90CF-E95BC473C168}_is1', 'InstallLocation', installLocation);
   Result := installLocation
  end; 
 end;



function InitializeUninstall(): Boolean;
var
  InstalledLocation : String;
  begin
   Result := PromptUntilProgramClosedOrInstallationCanceled( ProgramRunningOnUninstallMessage, True );

   // Unload the DLL, otherwise the dll psvince is not deleted
       UnloadDLL(ExpandConstant('{app}\psvince.dll'));

        if not Result then
        begin
          MsgBox( UninstallationCanceledMessage, mbInformation, MB_OK );
          end
            else
         begin
         InstalledLocation := GetInstalledLocation();
          ;DelTree('{InstalledLocation\*}', True, True, True);
            DelTree('{InstalledLocation}', True, True, True);
          ; DelTree('ExpandConstant({InstalledLocation\*})', True, True, True);
             end;
              end;

          [UninstallDelete]
             ;This works only if it is installed in default location
            Type: filesandordirs; Name: "{pf}\{#MyAppName}"

But I want to delete the folder along with the new files i.e. I want to delete nonempty folder in inno setup . How can I do it ?

like image 588
beginner Avatar asked Jul 21 '14 12:07

beginner


1 Answers

ya now its working , i used following code :

[UninstallDelete]
;This works only if it is installed in default location
Type: filesandordirs; Name: "{pf}\{#MyAppName}"


;This works if it is installed in custom location
Type: files; Name: "{app}\*"; 
Type: filesandordirs; Name: "{app}"
like image 130
beginner Avatar answered Nov 10 '22 17:11

beginner