mdrasted
asked on
How to start and then kill a process
How do I start a command line (DOS) process and then kill it from Delphi? My platform is NT.
Regards,
Morten
Regards,
Morten
You can call CreateProcess with cmd.exe as executable and keep the returned process handle (in TProcessInformation). Whenever you think it is time to close the process then you can try sending a WM_QUIT message to the process or (if it doesn't react) call KillProcess.
Ciao, Mike
Ciao, Mike
ASKER
Can you please give me an example on how to use CreateProcess?
Regards;
Morten
Regards;
Morten
Mike.
I dont think it is a good idea to remember the handle and use it to close the window again, because it may no longer exist.
-just a comment.
I dont think it is a good idea to remember the handle and use it to close the window again, because it may no longer exist.
-just a comment.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Peter, you don't need a window to post a message. All you need is a message queue which is automatically created when a thread calls GetMessage or PeekMessage the very first time. For these calls no window is needed but the command line program has indeed one so you can be sure that a message queue has been created.
Ciao, Mike
Ciao, Mike
ASKER
Thanks for your excellent help Mike!!
Regards,
Morten
Regards,
Morten
I'm pleased to help you and thank you for the A grading :-)
Ciao, Mike
Ciao, Mike
Ok Mike, i understand this but it was not my point.
If you have a handle to a process and this process dont exist anymore or the handle has been recreated to another process - is it not possible that this may be a problem ??
I'm not asking just for keeping the discussion going, but because i dont know!
Regards
Peter
If you have a handle to a process and this process dont exist anymore or the handle has been recreated to another process - is it not possible that this may be a problem ??
I'm not asking just for keeping the discussion going, but because i dont know!
Regards
Peter
No problem. If the process is already gone without that the application got notified of this fact (which one can prevent with the WaitFor* calls) then the APIs will just return False on return (PostThreadMessage and the like). The process ID as such is not used again, AFAIK, until the computer is rebooted.
Ciao, Mike
Ciao, Mike
You may search for it here.