mIRC Homepage
Posted By: pball Using com to kill a process - 14/05/11 12:27 AM
Sorry for the blatant request, but does anyone have something for killing processes in mirc. I'm guessing using com would be the only way to do it in an mirc script. Thanks for any help.
Posted By: FroggieDaFrog Re: Using com to kill a process - 14/05/11 01:36 AM
Found you something better, by an old friend of mine, FiberOptics:
Code:
; Usage: /killprocess <N> <process> 
; 
; Examples: 
; 
; /killprocess 0 notepad.exe to kill all processes 
; /killprocess 1 mirc.exe to kill the first instance of mIRC 
; 
; Requirements: mIRC 6.16 and Windows 2k or higher

alias killprocess {
  var %e = echo -ac info * /killprocess:
  if ($version < 6.16) { %e snippet requires mIRC 6.16 or higher | return }
  if ($1 !isnum 0-) || ($0 < 2) { %e <N> <process> with N zero or higher | return }
  var %a = a $+ $ticks, %b = b $+ %a, %c
  .comopen %a WbemScripting.SWbemLocator 
  if ($comerr) { %e error connecting to WMI | return }
  .comclose %a $com(%a,ConnectServer,1,dispatch* %b) 
  if ($com(%b)) .comclose %b $com(%b,ExecQuery,1,bstr*,SELECT $&
    Name FROM Win32_Process WHERE Name = $+(",$2-,"),dispatch* %a) 
  if (!$com(%a)) { %e error retrieving collection | return }
  %c = $comval(%a,0)
  if (!%c) { %e no such process $2 | return }
  if (!$1) {
    while (%c) {
      !.echo -q $comval(%a,%c,Terminate) 
      dec %c 
    } 
  }
  else !.echo -q $comval(%a,$1,Terminate) 
  :error
  if ($com(%a)) .comclose %a
  if ($com(%b)) .comclose %b
}

Posted By: pball Re: Using com to kill a process - 14/05/11 04:50 AM
Thanks that's exactly what i was imagining.
© mIRC Discussion Forums