Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinExec 1

Status
Not open for further replies.

eladna

Programmer
Dec 11, 2002
17
IL
Hi
I'm using the WinExec command

PCommand := PChar(Command);
WinExec(PCommand,SW_HIDE);

and when the program is running under "Windows 98" every time I use it, it stays open and can be close only by close program session (ctrl + alt + Delete)

so my questions are how do I close the WinExec command and how can I tell when it has stopped so I can continue with my program.
 
Use 'createproccess' instead, you can set a time to wait for termination.

Steve

Life is like a Grapefruit, sort of orangey-yellow and dimpled on the outside, wet and squidgy in the middle, it's got pips inside too. Oh and some people have half a one for breakfast. Ford Prefect.

Want to do more with TGML Download Star
 

This is a handler I use for createproccess

Code:
[COLOR=#0000FF]
{ Useage: Filename, The file to be executed
          Params, Any parameters that require passing to the file
          Timeout, Time to wait in mS. Pass the constant INFINITE to wait forever
          Visibility, Run window status e.g SW_SHOW, SW_MAXIMIZE
          It returns a string containing the last error if any
}
function WaitProcess(Filename: TFilename; Params: string;
         Timeout: DWORD; Visibility: integer): string;
var StartupInfo: TStartupInfo;
    ProcessInfo: TProcessInformation;
    WaitResult: integer;
begin
   ZeroMemory(@StartupInfo, SizeOf(TStartupInfo));
    with StartupInfo do
      begin
         cb := SizeOf(TStartupInfo);
         dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
         wShowWindow := Visibility;
       end;
    if fileexists(filename) or fileexists(params) then
      begin
         if (CreateProcess(nil, Pchar(Filename +' '+ Params), Nil, Nil,
                     False, NORMAL_PRIORITY_CLASS,
                     Nil, nil { pchar(extractfilepath(Params))}, StartupInfo, ProcessInfo))
            then
                begin
                    WaitResult := WaitForSingleObject(ProcessInfo.hProcess, Timeout);
                    if WaitResult = WAIT_TIMEOUT then
                       begin
                          result := 'Timeout has occured in waiting for result from compiler.';
                          TerminateProcess(ProcessInfo.hprocess, 1);
                          CloseHandle(ProcessInfo.hProcess);
                          CloseHandle(ProcessInfo.hThread);
                          exit;
                       end;
                    CloseHandle(ProcessInfo.hProcess);
                    CloseHandle(ProcessInfo.hThread);
                    Result := 'OK';
                end
            else
                result := 'Create Proccess failed ' + filename + ' '+ Params+ ' Error: '+inttostr(getlasterror);
      end
   else
      result := 'Process file does not exist';
end;

[/color]


Steve

Life is like a Grapefruit, sort of orangey-yellow and dimpled on the outside, wet and squidgy in the middle, it's got pips inside too. Oh and some people have half a one for breakfast. Ford Prefect.

Want to do more with TGML Download Star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top