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

Starting and killing a process

 [1/9] from: maarten::koopmans::surfnet::nl at: 19-Dec-2002 13:03


Hi list, I need to start and later on kill a process on windows. I can start using call and I know the name of the process, but how to kill it? And I also like to trap a "kill" using the system port so I can kill the subprocess. But... I have no idea how to use the system port, nor do I know the windows API too well (and its events , and, and, ...) I think I saw somebody posting some stuff (Gregg?), can anyboyd help me? (I noticed the call/info in the SDK, but... id is set to none :( ) Thanks in advance, Maarten

 [2/9] 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

 [3/9] from: maarten:koopmans:surfnet:nl at: 20-Dec-2002 8:09


Hi Gregg, Thanks! I'll look into those API's --maarten

 [4/9] from: sqlab:gmx at: 9-Jan-2003 9:26


Hello Maarten Did you suceed trying to start and stop a process. Maarten Koopmans wrote:
> Hi Gregg, > > Thanks! I'll look into those API's > > --maarten
I used win-lib: context [ shell-lib: load/library %shell32.dll execute: make routine! [ hwndParent [integer!] Operation [string!] File [string!] Parameters [string!] Directory [string!] ShowCmd [integer!] return: [integer!] ] shell-lib "ShellExecuteA" kernel-lib: load/library %kernel32.dll terminate: make routine! [ handle [integer!] Exitcode [integer!] return: [integer!] ] kernel-lib "TerminateProcess" ] But I always got 0 (meaning no success) as return value when using terminate. Is there an other and more successful way for ending a process under Windows? AR -- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!

 [5/9] from: maarten:koopmans:surfnet:nl at: 9-Jan-2003 10:50


Nope, haven't had the time... --Maarten

 [6/9] from: jurgens:akcorp at: 9-Jan-2003 15:40


[sqlab--gmx--net] wrote:
> >But I always got 0 (meaning no success) as return value when using >terminate. > >Is there an other and more successful way for ending a process under >Windows? > >AR >
You might check this article out and see if there is anything helpful here: http://www.pcmag.com/article2/0,4149,2265,00.asp HTH, Burt

 [7/9] from: sqlab:gmx at: 10-Jan-2003 9:37


Hello Burt Thanks for that reference. After thouroughly reading again some documentation about the C-API I think, I was wrong assuming that the return value of CreateProcess is already a handle. This and your reference let my try it again at the weekend. I will use an OpenProcess before the TerminateProcess command. AR
> [sqlab--gmx--net] wrote: > >
<<quoted lines omitted: 14>>
> HTH, > Burt
-- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!

 [8/9] from: jurgens:akcorp at: 10-Jan-2003 2:08


Glad it helped. Coincidentally, I have been grappling with the same problem today (although not in REBOL). I made the same error. Here are a couple of MS references if you do not have them already: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_information_str.asp It sounds like you probably know already but the last argument passed to the create process call comes back containing a pointer to a process info structure which contains the handle to the process. Burt [sqlab--gmx--net] wrote:

 [9/9] from: greggirwin:mindspring at: 10-Jan-2003 3:19


sgn> After thouroughly reading again some documentation about the C-API I think, sgn> I was wrong assuming that the return value of CreateProcess is already a sgn> handle. This and your reference let my try it again at the weekend. I will use sgn> an OpenProcess before the TerminateProcess command. CreateProcess returns the process handle in the process structure it fills. The actual return value for it is just a bool. -- Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted