ben projemde bir bat dosyasının içine dosta çalıştırmak için bir takım kodlar yazıyorum sonra
Kod: Tümünü seç
shellexecute(0,'open','c:\MOyedekleme\yedek.bat','','',sw_show);
s.a
Kod: Tümünü seç
shellexecute(0,'open','c:\MOyedekleme\yedek.bat','','',sw_show);
Kod: Tümünü seç
Cursor := crHourGlass;
repeat
Application.ProcessMessages;
until FileExists('d:\bitti.txt');
DeleteFile('d:\bitti.txt');
Cursor := crDefault;
ShowMessage('Bitti');
Kod: Tümünü seç
sl:=tstringlist.create;
sl.add('cd \mysql\bin');
sl.add('mysqldump.exe -u root -proot --databases veritabanı >yedek.txt');
sl.add('del c:\yedekleme\yedek.bat');
sl.savetofile('c:\yedekleme\yedek.bat');
Kod: Tümünü seç
Function MyExec(c_FileName,c_Params:String;l_wait:Boolean):Integer;
var
ei: TSHELLEXECUTEINFO;
begin
ei.cbSize := SizeOf(ei);
ei.Wnd := Application.Handle;
ei.lpVerb := 'OPEN';
ei.lpFile := pchar(c_filename);
ei.lpParameters := pchar(c_params);
ei.lpDirectory := '';
ei.fMask := SEE_MASK_NOCLOSEPROCESS;
ShellExecuteEx( @ei);
Result := ei.hInstApp;
if Result <= 32 // hata var
then Raise Exception.Create('Error ('+inttostr(Result)+') on Execute:'+c_FileName+' '+c_params);
else if l_wait then
WaitForSingleObject(ei.hProcess, INFINITE);
end;
Kod: Tümünü seç
procedure RunDosInMemo(DosApp:String;AMemo:TMemo) ;
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Security do
begin
nlength := SizeOf(TSecurityAttributes) ;
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe, @Security, 0) then
begin
Buffer := AllocMem(ReadBuffer + 1) ;
FillChar(Start,Sizeof(Start),#0) ;
start.cb := SizeOf(start) ;
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo) then
begin
repeat
Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100) ;
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT) ;
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil) ;
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer) ;
AMemo.Text := AMemo.text + String(Buffer) ;
until (BytesRead < ReadBuffer) ;
end;
FreeMem(Buffer) ;
CloseHandle(ProcessInfo.hProcess) ;
CloseHandle(ProcessInfo.hThread) ;
CloseHandle(ReadPipe) ;
CloseHandle(WritePipe) ;
end;
end;
procedure TForm1.Button1Click(Sender: TObject) ;
begin {button 1 code}
RunDosInMemo('chkdsk.exe c:\',Memo1) ;
end;
Kod: Tümünü seç
function ExecFileAndWait(const aCmdLine: String; Hidden, doWait: Boolean): Boolean;
var
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
// setup the startup information for the application
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
with StartupInfo do
begin
cb:= SizeOf(TStartupInfo);
dwFlags:= STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
if Hidden
then wShowWindow:= SW_HIDE
else wShowWindow:= SW_SHOWNORMAL;
end;
Result := CreateProcess(nil,PChar(aCmdLine), nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
if doWait then
if Result then
begin
WaitForInputIdle(ProcessInfo.hProcess, INFINITE);
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
end else Raise Exception.Create('Interbase Klasörü Bulunamadı');
end;