1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
const
GFIXNameWithFullPath = 'C:\Program files\Firebird\Firebird_2_0\bin\gfix.exe';
GBAKNameWithFullPath = 'C:\Program files\Firebird\Firebird_2_0\bin\gbak.exe';
ShutDownParamList = '-shut -attach 30 C:\DataBases\Firebird\Test_FB2.fdb -user SYSDBA -pass masterkey';
OnLineParamList = '-online C:\DataBases\Firebird\Test_FB2.fdb -user SYSDBA -pass masterkey';
BackupParamlist = '-B -T -user SYSDBA -pass masterkey C:\DataBases\Firebird\Test_FB2.fdb C:\DataBases\Firebird\Test_FB2.fbk';
RestoreParamList = '-REPLACE_DATABASE -user SYSDBA -pass masterkey -p 4096 C:\DataBases\Firebird\Test_FB2.fbk C:\DataBases\Firebird\Test_FB2.fdb';
implementation
{$R *.dfm}
uses
ShellAPI;
function LaunchExe(ExeName, ParamList: string): Boolean;
var
exInfo: TShellExecuteInfo;
exitcode: DWORD;
begin
result := False;
FillChar( exInfo, Sizeof(exInfo), 0 );
with exInfo Do Begin
cbSize:= Sizeof( exInfo ); // required!
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := Form1.Handle; // forms handle
lpVerb:= 'open';
lpFile:= Pchar( ExeName );
lpParameters := PChar( Paramlist );
nShow := SW_HIDE;
End;
if ShellExecuteEx( @exInfo ) Then Begin
While GetExitCodeProcess( exinfo.hProcess, exitcode ) and
(exitcode = STILL_ACTIVE)
Do
Sleep( 500 );
CloseHandle( exInfo.hProcess );
if exitcode <> 0 then
ShowMessage('Echec Code ' + IntToStr(exitCode))
else
result := True;
End
Else
ShowMessage(SysErrorMessage( GetLastError ));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not LaunchExe(GFIXNameWithFullPath, ShutdownParamlist) then Exit;
if not LaunchExe(GBAKNameWithFullPath, BackupParamlist) then Exit;
if not LaunchExe(GBAKNameWithFullPath, RestoreParamlist) then Exit;
LaunchExe(GFIXNameWithFullPath, OnlineParamlist);
end;
end. |
Partager