SHOW:
|
|
- or go back to the newest paste.
| 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
|
| 23 | + | |
| 24 | App := '"' + App + '"'; | |
| 25 | if (App <> '') and (CmdLine <> '') then | |
| 26 | App := App + ' '; | |
| 27 | if CreateProcess( nil, PChar( App + CmdLine ), nil, | |
| 28 | nil, FALSE, Flags, nil, DfltDir, Startup, | |
| 29 | ProcInf ) then | |
| 30 | begin | |
| 31 | if WaitForSingleObject( ProcInf.hProcess, TimeOut ) = WAIT_OBJECT_0 then | |
| 32 | begin | |
| 33 | CloseHandle( ProcInf.hProcess ); | |
| 34 | Result := TRUE; | |
| 35 | end | |
| 36 | else | |
| 37 | begin | |
| 38 | if ProcID <> nil then | |
| 39 | ProcID^ := ProcInf.hProcess; | |
| 40 | end; | |
| 41 | CloseHandle( ProcInf.hThread ); | |
| 42 | end; | |
| 43 | end; |