Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Starting and killing a process

From: greggirwin:mindspring at: 19-Dec-2002 10:14

Hi Maarten, MK> I need to start and later on kill a process on windows. I can start MK> using call and I know the name of the process, but how to kill it? MK> And I also like to trap a "kill" using the system port so I can kill the MK> subprocess. CALL probably isn't going to work, as it doesn't return you a process ID. You'll likely want to use API calls to launch it (WinExec or CreateProcess) rather than walking lists to find the process you want (i.e. with EnumProcesses) after using CALL. Then you can use OpenProcess with the TaskID returned by WinExec, which gives you a process ID. You can use that with TerminateProcess, but that's not always the best way to do things; it depends on the app and what you need to do, or how risky it might be based on what resources the process has allocated and such. Under W2K/XP, you're much safer of course. You can use GetExitCodeProcess to find out if a process is still active, or you can use something like WaitForSingleObject - flexible but the synchronization stuff under Windows has many faces and can be a bit confusing at times as to what's the most appropirate mechanism to use. Not really my forte though. You can also kill processes by finding the handle to their main window (or any window really) and sending it a WM_CLOSE or WM_DESTROY message and handling things appropriately in the receiving app. You can also pump keystrokes to apps. Some apps are picky, so the best approach is often based on what app you're talking to and whether you can modify it to work the way you want. Lots of options in any case. -- Gregg