mIRC Home    About    Download    Register    News    Help

Print Thread
#118217 23/04/05 09:05 AM
Joined: Apr 2005
Posts: 53
A
aDevil Offline OP
Babel fish
OP Offline
Babel fish
A
Joined: Apr 2005
Posts: 53
Is there a way to list the running tasks in the computer?:)
And if exists how can I do?:)

#118218 23/04/05 11:00 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Try this:
Code:
alias listprocesses {
  echo -ae Listing running processes...
  tokenize 32 listprocesses $+ $ticks Error!
  .comopen $1tmpa WbemScripting.SWbemLocator
  if $comerr { echo 4 -a $2 | goto end }
  .comclose $1tmpa $com($1tmpa,ConnectServer,3,dispatch* $1tmpb)
  if $com($1tmpb) { .comclose $v1 $com($v1,ExecQuery,1,bstr*,SELECT $&
    name $+ $chr(44) $+ executablepath FROM win32_process,dispatch* $1) }
  if !$com($1) { echo 4 -a $2 | goto end }
  var %i = 1, %a = $comval($1,0)
  while %i <= %a {
    echo -a $comval($1,%i,name) ( $+ $comval($1,%i,executablepath) $+ )
    inc %i
  }
  .comclose $1
  :end
  echo -ae Finished listing running processes.
}

Type /listprocesses


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#118219 23/04/05 12:25 PM
Joined: Apr 2005
Posts: 53
A
aDevil Offline OP
Babel fish
OP Offline
Babel fish
A
Joined: Apr 2005
Posts: 53
Thanks very much. And I can close with mirc the tasks?

#118220 23/04/05 01:12 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Code:
alias closeprocess {
  tokenize 32 closeprocess $+ $ticks $int($1) $remove($2-,")
  if $2 !isnum 0- || $3 == $null { echo -cei info * /closeprocess: invalid parameters | halt }
  .comopen $1tmpa WbemScripting.SWbemLocator
  if $comerr { echo -cei info * /closeprocess: COM error | halt }
  .comclose $1tmpa $com($1tmpa,ConnectServer,1,dispatch* $1tmpb)
  if $com($1tmpb) { .comclose $v1 $com($v1,ExecQuery,1,bstr*,SELECT name $&
    FROM win32_process WHERE name=' $+ $3-',dispatch* $1) }
  if !$com($1) { echo -cei info * /closeprocess: COM error | halt }
  if !$2 {
    var %i = $comval($1,0)
    while %i {
      !.echo -q $comval($1,%i,terminate)
      dec %i
    }
  }
  else !.echo -q $comval($1,$2,terminate)
  .comclose $1
}

Syntax is
/closeprocess N processname.exe
closes the Nth running instance of processname.exe. If N = 0, it closes all instances.

Example 1: /closeprocess 2 notepad.exe
closes the second Notepad window

Example 2: /closeprocess 0 notepad.exe
closes all Notepad windows


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#118221 23/04/05 02:12 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Some remarks.
  • Apart from the code you've received, if you are on Windows XP, you can use taskkill, an XP-builtin utility that can kill 1 or more processes in 1 line from within mIRC with /run.

    Earlier OS'es are as far as I'm aware not builtin with such tool, but can download Microsoft's kill.exe for example here. It's 35kb, works on any OS, and can be called with /run as well.
  • The code you got works on Windows ME, 2000, XP, 2003

    Windows 95/98/NT4 SP4 users can download WMI from Microsoft in order to make it work here
  • Code requires mIRC 6.16, because it uses $comval which was only added then.
  • More information can be found here: WMI
  • Some AVG's like Norton for example might turn off Windows Scripting for safety measures. In this case any code using $com will not work.
  • I thought I should add this information for anyone trying out the code, as it will not work if you don't meet 1 or more of the requirements.

#118222 23/04/05 08:55 PM
Joined: Apr 2005
Posts: 53
A
aDevil Offline OP
Babel fish
OP Offline
Babel fish
A
Joined: Apr 2005
Posts: 53
Thanks the help guys, it is working for me very good smile I like it


Link Copied to Clipboard