Подождать завершения DOS-задачи 3
|
Молодого программиста спрашивают: что ты, мол, подружку себе не заводишь? Пора бы уже.. Тот отвечает:
- Зачем, если есть компьютер?
|
function TForm1.StartWithShell(Prog, par, Verz: string;
var hProcess: THandle): DWord;
var
exInfo: TShellExecuteInfo;
begin
hProcess := 0;
FillChar(exInfo, Sizeof(exInfo), 0);
with exInfo do
begin
cbSize:= Sizeof(exInfo);
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := 0;
lpVerb:= 'open';
lpParameters := PChar(par);
lpFile:= Pchar(prog);
nShow := SW_HIDE;
end;
Result := ERROR_SUCCESS;
if ShellExecuteEx(@exInfo) then
hProcess := exinfo.hProcess
else
Result := GetLastError;
end;
function TForm1.StartProgramm : Boolean;
var
r, ExitCode: DWord;
err: string;
hProcess: THandle;
begin
Result := False;
r := StartWithShell('rar.exe', , 'c:\windows\system',
hProcess);
if r = ERROR_SUCCESS then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(hProcess, ExitCode);
until
ExitCode <> STILL_ACTIVE;
result := true;
end
else
begin
case r of
ERROR_FILE_NOT_FOUND : err:='The specified file was not found.';
ERROR_PATH_NOT_FOUND : err:='The specified path was not found.';
ERROR_DDE_FAIL : err:='The DDE transaction failed.';
ERROR_NO_ASSOCIATION : err:='There is no application associated ' +
'with the given filename extension.';
ERROR_ACCESS_DENIED : err:='Access denied';
ERROR_DLL_NOT_FOUND : err:='DLL not found';
ERROR_CANCELLED : err:='The function prompted the user for the ' +
'location of the application, but the user cancelled the request.';
ERROR_NOT_ENOUGH_MEMORY: err:='Not enough memory';
ERROR_SHARING_VIOLATION: err:='A sharing violation occurred.';
else
err := 'Unknown';
end;
MessageDlg('Error: ' + err, mtError, [mbOk], 0);
end;
end;
|
|