:: |
Autor |
Poruka |
Doktor ~Sanjicino*slculence~
![~Sanjicino*slculence~ ~Sanjicino*slculence~](/images/ranks/stars_orange.gif)
![](images/avatars/1176565723449c4a8bc1d54.jpg) |
Godine: 38
Datum registracije: 17 Nov 2005 Poruke: 4264 Mesto: Novi Sad
![blank.gif](images/flags/blank.gif)
|
|
Ova primer prikazuje funckiju koja pokreće konzolnu aplikaciju (nalik DOSu) ili BAT komandni fajl a izlazne podatke snima u Memo1 objekat.
Code: |
private
function RunCaptured(const _dirName, _exeName, _cmdLine: string): Boolean;
{....}
function TForm1.RunCaptured(const _dirName, _exeName, _cmdLine: string): Boolean;
var
start: TStartupInfo;
procInfo: TProcessInformation;
tmpName: string;
tmp: Windows.THandle;
tmpSec: TSecurityAttributes;
res: TStringList;
return: Cardinal;
begin
Result := False;
try
// Postavljanje Temporary fajla…
tmpName := 'Test.tmp';
FillChar(tmpSec, SizeOf(tmpSec), #0);
tmpSec.nLength := SizeOf(tmpSec);
tmpSec.bInheritHandle := True;
tmp := Windows.CreateFile(PChar(tmpName),
Generic_Write, File_Share_Write,
@tmpSec, Create_Always, File_Attribute_Normal, 0);
try
FillChar(start, SizeOf(start), #0);
start.cb := SizeOf(start);
start.hStdOutput := tmp;
start.dwFlags := StartF_UseStdHandles or StartF_UseShowWindow;
start.wShowWindow := SW_Minimize;
// Startovanje programa
if CreateProcess(nil, PChar(_exeName + ' ' + _cmdLine), nil, nil, True,
0, nil, PChar(_dirName), start, procInfo) then
begin
SetPriorityClass(procInfo.hProcess, Idle_Priority_Class);
WaitForSingleObject(procInfo.hProcess, Infinite);
GetExitCodeProcess(procInfo.hProcess, return);
Result := (return = 0);
CloseHandle(procInfo.hThread);
CloseHandle(procInfo.hProcess);
Windows.CloseHandle(tmp);
// dodavanje izlaznih podataka u Memo1
res := TStringList.Create;
try
res.LoadFromFile(tmpName);
Memo1.Lines.AddStrings(res);
finally
res.Free;
end;
Windows.DeleteFile(PChar(tmpName));
end
else
begin
Application.MessageBox(PChar(SysErrorMessage(GetLastError())),
'RunCaptured Error', MB_OK);
end;
except
Windows.CloseHandle(tmp);
Windows.DeleteFile(PChar(tmpName));
raise;
end;
finally
end;
end;
|
Primer korišćenja:
Code: |
procedure TForm1.Button1Click(Sender: TObject);
begin
RunCaptured('C:\', 'cmd.exe', '/c dir');
end;
|
|
_________________ ~*~Vojim svoje srculence najvise na svetu ~*~ :322:
![](http://www.domaci.de/sanjica_021/doktor/banner.gif) |
|
|
|
![](templates/subDomaci/images/spacer.gif) |
|
|
Vi ne možete otvarati nove teme u ovom forumu Vi ne možete odgovarati na teme u ovom forumu Vi ne možete menjati Vaše poruke u ovom forumu Vi ne možete brisati Vaše poruke u ovom forumu Vi ne možete glasati u anketama u ovom forumu Vi ne možete postavljati fajlove u ovom forumu Vi ne možete preuzeti fajlove sa ovog foruma
|
|