Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ExecuteWait( const AppPath, CmdLine, DfltDirectory: String;
- Show: DWORD; TimeOut: DWORD; ProcID: PDWORD ): Boolean;
- var Flags: DWORD;
- Startup: TStartupInfo;
- ProcInf: TProcessInformation;
- DfltDir: PChar;
- App: String;
- begin
- Result := FALSE;
- Flags := CREATE_NEW_CONSOLE;
- if Show = SW_HIDE then
- Flags := Flags or CREATE_NO_WINDOW;
- ZeroMemory( @Startup, SizeOf( Startup ) );
- Startup.cb := Sizeof( Startup );
- Startup.wShowWindow := Show;
- Startup.dwFlags := STARTF_USESHOWWINDOW;
- if ProcID <> nil then
- ProcID^ := 0;
- DfltDir := nil;
- if DfltDirectory <> '' then
- DfltDir := PChar( DfltDirectory );
- App := AppPath;
- if (App <> '') and (App[1] <> '"') and (pos( String(' '), App ) > 0) then
- App := '"' + App + '"';
- if (App <> '') and (CmdLine <> '') then
- App := App + ' ';
- if CreateProcess( nil, PChar( App + CmdLine ), nil,
- nil, FALSE, Flags, nil, DfltDir, Startup,
- ProcInf ) then
- begin
- if WaitForSingleObject( ProcInf.hProcess, TimeOut ) = WAIT_OBJECT_0 then
- begin
- CloseHandle( ProcInf.hProcess );
- Result := TRUE;
- end
- else
- begin
- if ProcID <> nil then
- ProcID^ := ProcInf.hProcess;
- end;
- CloseHandle( ProcInf.hThread );
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment