mIRC Homepage
Posted By: MetallicAchu Running Processes. - 10/12/04 04:06 PM
I wish to get a list of working processes on my computer through scripting.
Is this possible?

I've built a command that activates Winrar, and I need it to know when it stops working.

Thanks!
Posted By: qwerty Re: Running Processes. - 10/12/04 04:33 PM
It is possible to get a list of all running processes using $com() and WMI (look at examples #2 and #3 in the help file regarding $com to get an idea). However, before I write such a script for you, you may want to look into an alternative: it is possible to make mirc run a program and wait for it to finish, again using COM objects. This way you don't have to check repeatedly if the program's finished. All you need to do is install this alias and use /xrun -w winrar <arguments> instead of /run winrar <arguments>.
Posted By: LethPhaos Re: Running Processes. - 10/12/04 05:08 PM
And if I want to stop winamp from my mIRC, not just know when it has been stopped?
Posted By: tidy_trax Re: Running Processes. - 10/12/04 05:38 PM
Code:
alias isprocess {
  if ($isid) {
    if ($2 !isnum 1-) { tokenize 32 $$1 1 }
    var %a = a $+ $ticks, %b = b $+ $ticks, %c = c $+ $ticks, %i = 1
    .comopen %a WbemScripting.SWbemLocator
    if ($com(%a)) {
      .comclose %a $com(%a,ConnectServer,3,dispatch* %b)
      if ($com(%b)) {
        .comclose %b $com(%b,ExecQuery,3,string,SELECT Name FROM Win32_Process WHERE Name=" $+ $1",dispatch* %c)
        if ($com(%c)) { 
          if ($comval(%c,$2,Name) == $1) {
            .comclose %c
            return $true
          }
        }
      }
    }
    if ($com(%a)) { .comclose %a }
    if ($com(%b)) { .comclose %b }
    if ($com(%c)) { .comclose %c }
    return $false
  }
}
alias endprocess {
  if ($isid) {
    if ($2 !isnum 1-) { tokenize 32 $$1 1 }
    var %a = a $+ $ticks, %b = b $+ $ticks, %c = c $+ $ticks, %i = 1
    .comopen %a WbemScripting.SWbemLocator
    if ($com(%a)) {
      .comclose %a $com(%a,ConnectServer,3,dispatch* %b)
      if ($com(%b)) {
        .comclose %b $com(%b,ExecQuery,3,string,SELECT Name FROM Win32_Process WHERE Name=" $+ $1",dispatch* %c)
        if ($com(%c)) {
          if ($comval(%c,$2,Name) == $1) {
            .echo -q $comval(%c,$2,Terminate)
            .comclose %c
            return $true
          }
        }
      }
    }
    if ($com(%a)) { .comclose %a }
    if ($com(%b)) { .comclose %b }
    if ($com(%c)) { .comclose %c }
    return $false
  }
}


$isprocess(<process>[,N]) - returns $true if there's an Nth process for <process>, otherwise $false.
$endprocess(<process>[,N]) - returns the same as $isprocess(), but also ends the Nth process for <process>.

Example:

Code:
if ($isprocess(mirc.exe,1)) { .echo -q $endprocess(mirc.exe,1) }
Posted By: MetallicAchu Re: Running Processes. - 10/12/04 07:46 PM
Quote:
It is possible to get a list of all running processes using $com() and WMI (look at examples #2 and #3 in the help file regarding $com to get an idea). However, before I write such a script for you, you may want to look into an alternative: it is possible to make mirc run a program and wait for it to finish, again using COM objects. This way you don't have to check repeatedly if the program's finished. All you need to do is install this alias and use /xrun -w winrar <arguments> instead of /run winrar <arguments>.


Thanks a lot!
It really helped me, and now the script works out just fine!

Thanks again!
© mIRC Discussion Forums