Mega Code Archive

 
Categories / Delphi / Examples
 

Using WinZip as a backup tool

Title: Using WinZip as a backup tool Question: Using WinZip as a backup tool Answer: This article will explain about using WinZip as a backup tool in Delphi. This requires WinZip 7.0 or later. Setup WinZip to run with Classic Interface and in "help\Tip Of the Day" menu, set it as "Never Show Tip". Here is the code: //Add uses Registry; //Define type TTypeOfTran = (zBackup, zRestore); function getWinZipPath: String; var Registry: TRegistry; WZRegKey: String; begin Result := ''; WZRegKey := '\Software\Microsoft\Windows\ CurrentVersion\App Paths\winzip32.exe'; Registry := TRegistry.Create; try Registry.RootKey := HKEY_LOCAL_MACHINE; if (Registry.OpenKey(WZRegKey, False)) then begin Result := Registry.ReadString(''); Registry.CloseKey; end; finally Registry.Free; end; end; procedure BackRes(TypeOfTran: TTypeOfTran); var ExecPath: String; begin if (TypeOfTran=zBackup) then ExecPath := getWinZipPath+ ' -min -a -s"Password" C:\Backup\Backup.Zip C:\MySrc\*.*' else if (TypeOfTran=zRestore) then ExecPath := getWinZipPath+ ' -min -e -o -j -s"Password" C:\Backup\Backup.Zip C:\Restore'; { -min: Run WinZip as minimized. -a: Add files. -s: Encript with password. -e: Extract files. -o & -j: Overwrite existing files without prompting. } WinExec(PChar(ExecPath), SW_Hide); end; procedure TForm1.btnBackupClick(Sender: TObject); begin BackRes(zBackup); end; procedure TForm1.btnRestoreClick(Sender: TObject); begin BackRes(zRestore); end; Conclusion This is just a simple sample function to define the usage, based on this you can elaborate like providing options to the user to choose the backup or restore destination etc.