2014-07-21 43 views
0

我已經創建了一個使用Inno Setup的安裝程序,其中包含5個文件。我添加了一個附加功能,以便用戶可以將其安裝在自定義路徑中。如何刪除inno setup中的非空文件夾

安裝後,將在所選路徑中創建一個文件夾。現在我將複製此文件夾中的其他文件。但未安裝後,以下情況發生:

  1. 讓用戶將其安裝在默認的位置,然後一個新的文件夾說MyFolder文件是在該位置創建,現在用戶創建該文件夾中的2個新的文件,並將它們複製。 卸載後沒有問題;我的文件夾將與2個新文件一起被刪除(安裝後創建)。

  2. 現在讓用戶將其安裝在自定義位置,然後一個新的文件夾表示myfolder在該位置創建,現在用戶創建2個新文件並將它們複製到此文件夾中。 卸載myfolder後不會刪除,因爲其中有2個新文件(它們是在安裝後創建的)。

這裏是我的代碼:

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}" 

但我想用新的文件,即我要在創新安裝,刪除非空文件夾一併刪除文件夾。 我該怎麼辦?

+0

的可能重複(http://stackoverflow.com/questions/643547/how-to -configure-inno-setup-to-uninstall-everything) –

+0

正如在鏈接問題中所建議的,這樣做是一個壞主意。 – Miral

回答

4

雅現在的工作,我用下面的代碼:?如何配置Inno Setup的卸載一切]

[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}" 
相關問題