Guest User

Untitled

a guest
Mar 14th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.36 KB | None | 0 0
  1. function ExecuteWait( const AppPath, CmdLine, DfltDirectory: String;
  2.          Show: DWORD; TimeOut: DWORD; ProcID: PDWORD ): Boolean;
  3. var Flags: DWORD;
  4.     Startup: TStartupInfo;
  5.     ProcInf: TProcessInformation;
  6.     DfltDir: PChar;
  7.     App: String;
  8. begin
  9.   Result := FALSE;
  10.   Flags := CREATE_NEW_CONSOLE;
  11.   if Show = SW_HIDE then
  12.     Flags := Flags or CREATE_NO_WINDOW;
  13.   ZeroMemory( @Startup, SizeOf( Startup ) );
  14.   Startup.cb := Sizeof( Startup );
  15.   Startup.wShowWindow := Show;
  16.   Startup.dwFlags := STARTF_USESHOWWINDOW;
  17.   if ProcID <> nil then
  18.     ProcID^ := 0;
  19.   DfltDir := nil;
  20.   if DfltDirectory <> '' then
  21.     DfltDir := PChar( DfltDirectory );
  22.   App := AppPath;
  23.   //if (pos( KOLString(' '), App ) > 0) and (pos( String('"'), App ) <= 0) then
  24.   if (App <> '') and (App[1] <> '"') and (pos( String(' '), App ) > 0) then
  25.     App := '"' + App + '"';
  26.   if (App <> '') and (CmdLine <> '') then
  27.     App := App + ' ';
  28.   if CreateProcess( nil, PChar( App + CmdLine ), nil,
  29.      nil, FALSE, Flags, nil, DfltDir, Startup,
  30.      ProcInf ) then
  31.   begin
  32.     if WaitForSingleObject( ProcInf.hProcess, TimeOut ) = WAIT_OBJECT_0 then
  33.     begin
  34.       CloseHandle( ProcInf.hProcess );
  35.       Result := TRUE;
  36.     end
  37.       else
  38.     begin
  39.       if ProcID <> nil then
  40.         ProcID^ := ProcInf.hProcess;
  41.     end;
  42.     CloseHandle( ProcInf.hThread );
  43.   end;
  44. end;
Advertisement
Add Comment
Please, Sign In to add comment