Rich,
Thought I'd chime in with code that I've used for the very same
process. It worked on D7... HTH.
unit Process;
interface
uses
Classes, Windows, SysUtils;
function ExecuteWait(Path, Command, Params: String; ShowWindow: Word;
Output: TStringList): DWord;
function GetTempFile: String;
implementation
function ExecuteWait(Path, Command, Params: String; ShowWindow: Word;
Output: TStringList): DWord;
// Build a temporary filename -----------
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
saAttr: TSecurityAttributes;
hOut, hInp: THandle;
outFile, inpFile: String;
begin
if Path = '' then begin
Output.Add('Path not specified: ' + Path);
exit;
end;// if Path
saAttr.nLength := sizeof(TSecurityAttributes);
saAttr.bInheritHandle := True;
saAttr.lpSecurityDescriptor := nil;
hOut := STD_OUTPUT_HANDLE;
hInp := STD_INPUT_HANDLE;
if Output <> nil then begin
outFile := GetTempFile;
hOut := CreateFile(PChar(outFile),
GENERIC_READ or GENERIC_WRITE,
0,
@saAttr,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY,
0);
end; // if Output <> nil
ZeroMemory(@ProcessInfo, SizeOf(TProcessInformation));
ZeroMemory(@StartupInfo, SizeOf(TStartupInfo));
with StartupInfo do begin
cb := SizeOf(TStartupInfo);
hStdOutput := hOut;
hStdError := hOut;
hStdInput := hInp;
wShowWindow := ShowWindow;
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
end; // with
if CreateProcess(nil,
PChar('"'+
Path + Command + '" ' + Params),
@saAttr,
@saAttr,
True,
0,
nil,
PChar(Path),
StartupInfo,
ProcessInfo) then begin
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
repeat
GetExitCodeProcess(ProcessInfo.hProcess, Result);
//Application.ProcessMessages;
until (Result <> STILL_ACTIVE);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
if Output <> nil then begin
CloseHandle(hOut);
Output.LoadFromFile(outFile);
end; // if Output <> nil
DeleteFile(inpFile);
DeleteFile(outFile);
end // if CreateProcess(...
else
Output.Add('Create Process failed. Code: ' +
IntToStr(GetLastError()));
end; //
function GetTempFile: String;
var
DirBuf, FileBuf: Array [0..255] of char;
begin
GetTempPath(Length(DirBuf), DirBuf);
GetTempFileName(DirBuf, 'tmp', 0, PChar(@FileBuf));
Result := FileBuf;
end;//GetTempFile
end.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi