mIRC Home    About    Download    Register    News    Help

Print Thread
Script slowing mIRC down #112904 27/02/05 07:35 PM
Joined: Aug 2004
Posts: 237
L
LethPhaos Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
Code:
on *:connect:{
  checkconnected | .timercheckconnected 0 3600 checkconnected
  if ( $group(#coolmonnetwstats) == on ) { coolmonnetwstats }
  .timeripupdateboot 1 3 ipupdate | .timeripupdate 0 900 ipupdate
  .timerstartcoolmon 1 3 coolmon
}
alias ipupdate {
  write -c "C:\Program Files\CoolMon\Extensions\Coolmon External IP Result.txt" $ip
  write -n "C:\Program Files\CoolMon\Extensions\Coolmon External IP Result.txt" $asctime(HH:nn)
  inc %counter.ipupdate
  echo -ts CoolMon ip-update n $+ %counter.ipupdate completed...
}
alias checkconnected {
  tokenize $char(:) $duration($online,3)
  if ( $1 = 1337 ) { beep 1000 | amsg mIRC has been connected4 $1 hours since $asctime($folderdate($mircdir),[yyyy ddd dd mmm][HH:nn:ss]) (automessage) }
  if ( $1 = 1234 ) { beep 100 | amsg mIRC has been connected4 $1 hours since $asctime($folderdate($mircdir),[yyyy ddd dd mmm][HH:nn:ss]) (automessage) }
  if ( $1 = 1500 ) { beep 100 | amsg mIRC has been connected4 $1 hours since $asctime($folderdate($mircdir),[yyyy ddd dd mmm][HH:nn:ss]) (automessage) }
}
#coolmonnetwstats off
alias coolmonnetwstats {
  var %cpu $left($dll(darkenginex.dll,cpuload,_),3)
  if ( !$isprocess(wscript.exe) && $isprocess(coolmon.exe) && %cpu <= 60) {
    write -cn "C:\Program Files\CoolMon\extensions\CoolMon Network Result Time.txt" $asctime(HH:nn:ss)    
    run "networkStatus v2.1.vbs"
    inc %counter.netwupdate
    inc %counter.netwupdateloop
    if ( %counter.netwupdateloop = 500 ) {
      echo -ts CoolMon Network Status-update n $+ %counter.netwupdate completed...
      %counter.netwupdateloop = 0
    }
  }
  .timernetwstats 1 5 coolmonnetwstats
}
#coolmonnetwstats end
alias coolmonnetwstatson { .enable #coolmonnetwstats | coolmonnetwstats | echo 4 * CoolMon network stats: 3Updating... }
alias coolmonnetwstatsoff { .disable #coolmonnetwstats | .timernetwstats off | echo 4 * CoolMon network stats: 3Not updating... }
menu channel,status {
  $style($iif($isprocess(telemeter3.exe),1,0)) Use Telemeter: { $iif($isprocess(telemeter3.exe),notelemeter,tm) }
  Coolmon
  .$style($iif($isprocess(coolmon.exe),1,0)) Use Coolmon: { $iif($isprocess(coolmon.exe),nocoolmon,coolmon) }
  .$style($iif($group(#coolmonnetwstats) == on,1,0)) Update CoolMon netw stats: { $iif($group(#coolmonnetwstats) == on,coolmonnetwstatsoff,coolmonnetwstatson) }
}
alias coolmon run coolmon
alias nocoolmon kill coolmon.exe | refreshtray

alias telemeter tm
alias notelemeter kill telemeter3.exe | refreshtray
alias tm run telemeter

alias heatup run heatup
alias noheatup kill heatup.exe | refreshtray

alias refreshtray {
  var %a = $window(-1).w,%b = %a - 256
  ; ^ Screen width and same minus 256
  var %c = $window(-1).h,%d = %c - 48
  ; ^ Screen height and same minus 48
  var %x = $mouse.dx $mouse.dy
  ; Stores current position

  while %b < %a {
    : loop until cursor is at far right of screen
    while %d < %c {
      ; loop until cursor is at bottom of screen
      dll mouseevents.dll movemouse %b %d
      ; ^ moves cursor downwards in 10 pix increment (/inc line below)
      inc %d 10
    }
    %d = %c - 50
    ; Reset height var
    dll mouseevents.dll movemouse %b %d
    ; ^ moves cursor to the right in 10 pix increment (/inc line below)
    inc %b 10
  }
  dll mouseevents.dll movemouse %x
  ; Restores cursor position
}
alias isprocess {
  ; check if process exists
  ; $isprocess(<process>[,N]) - returns $true if there's an Nth process for <process>, otherwise $false.
  ; example: if ($isprocess(mirc.exe,1)) { .echo -q $endprocess(mirc.exe,1) }
  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 {
  ; kill running process
  ; $endprocess(<process>[,N]) - returns the same as $isprocess(), but also ends the Nth process for <process>.
  ; example: if ($isprocess(mirc.exe,1)) { .echo -q $endprocess(mirc.exe,1) }
  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
  }
}
alias kill $endprocess($1,1)

This script contains some code I got on this forum.
The problem is, when I have the coolmonnetworkstatsupdate enabled, mIRC gets very slow. This is because it has to check the $isprocess pretty much then I suppose.
Is there a better way to do this?

Re: Script slowing mIRC down #112905 27/02/05 07:36 PM
Joined: Aug 2004
Posts: 237
L
LethPhaos Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
Thanks in advance to everyone who tries to understand this mess!!!

Re: Script slowing mIRC down #112906 27/02/05 08:29 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias coolmonnetwstats {
  var %cpu $left($dll(darkenginex.dll,cpuload,_),3)



  if ( (%cpu <= 60) && !$isprocess(wscript.exe) && $isprocess(coolmon.exe) ) {
or
  if ( (%cpu <= 60) && $isprocess(coolmon.exe) && !$isprocess(wscript.exe) ) {



Since if the %cpu value is 61 or greater you wont do it you should check that first, then it never needs to check the $isprocess's if %cpu is 61 or up.

Then depending on which you think is more likely to be false place that as the first $isprocess
if wscript.exe is almost always running use first option
If coolmon.exe is almost never running use second option

Either well reduce the $isprocess load during the top 40% of CPU usage.

Re: Script slowing mIRC down #112907 27/02/05 08:31 PM
Joined: Aug 2004
Posts: 237
L
LethPhaos Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
Thanx!!!
It sure helps already, but when cpu stress is less than 60 percent the script makes mirc slow down every +/- 5secs for some miliseconds. I can live with that, but if I (anybody) could solve it it would be nicer smile.
Is it because it calls the vbscript or just because the $isprocess isn't that quick?

Last edited by LethPhaos; 27/02/05 08:35 PM.
Re: Script slowing mIRC down #112908 27/02/05 08:47 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
It's because you are abusing the $isprocess identifier. What it does is use com objects to connect to the Windows Management Instrumentation (WMI), perform a query on it, and check for existance of the process.

It's crazy to perform that every 5 seconds, and is not surprising at all that it lags your mIRC.

Think of it as an identifier that you should use as sparingly as possible, so definitely not the way you do in your channel/status popups, needlessly checking for it 2 times, and definitely not in a timer to check every 5 seconds.

If I were you, i'd make a small alias to start those programs from mIRC instead with a switch %on. Since you disable them from mIRC, you can then set it to %off, and all this checking for the existance of the process is obsolete then.

If you sometimes start the programs before being in mIRC, then just do 1 check in the on start event to set the switches.

Greets


Gone.
Re: Script slowing mIRC down #112909 27/02/05 08:50 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
$isprocess isn't very quick because of the way it finds out whether or not the process is running, if you had mentioned you'd need to use it frequently when you asked for the snippet, I would of suggested a different method like a dll.


New username: hixxy
Re: Script slowing mIRC down #112910 27/02/05 09:28 PM
Joined: Aug 2004
Posts: 237
L
LethPhaos Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Aug 2004
Posts: 237
do you know a dll for that?

Re: Script slowing mIRC down #112911 27/02/05 09:35 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Try this.


New username: hixxy
Re: Script slowing mIRC down #112912 27/02/05 10:53 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Apart from the dll that tidy recommended (which I haven't tried), there are two fast alternatives: either use $comcall() (and a few aliases) instead of $com(), so that the process check is done in a separate thread, or move some of the work outside of mirc (in a .vbs for example). Unfortunately, both ways would mean rewriting your script almost from scratch.

An effective way to speed up your script (although not as much as the previous two solutions) without changing it too much is to modify $isprocess to check for two or more processes with a single ConnectServer/ExecQuery call. I modified $isprocess and /coolmonnetwstats accordingly, you can give them a try:
Code:
alias coolmonnetwstats {
  var %cpu $left($dll(darkenginex.dll,cpuload,_),3)
  ; if wscript.exe isn't running but coolmon.exe is, $isprocess returns 2
  ; (10 in binary: the first bit, which corresponds to the first process 
  ; that you specified (wscript.exe), is 0. The 2nd bit (coolmon.exe) is 1)
  if (%cpu <= 60 && $isprocess(wscript.exe|coolmon.exe) == 2) {
    write -cn "C:\Program Files\CoolMon\extensions\CoolMon Network Result Time.txt" $asctime(HH:nn:ss)    
    run "networkStatus v2.1.vbs"
    inc %counter.netwupdate
    inc %counter.netwupdateloop
    if ( %counter.netwupdateloop = 500 ) {
      echo -ts CoolMon Network Status-update n $+ %counter.netwupdate completed...
      %counter.netwupdateloop = 0
    }
  }
  .timernetwstats 1 5 coolmonnetwstats
}
alias isprocess {
  ; checks if process(es) exist(s)
  ; $isprocess(<process1[|process2|process3|...]>[,N]) - returns 1 if there's an Nth process for <process>, otherwise 0.
  ; if more than one process names are specified, N is assumed 1 and $isprocess() returns a number where each bit
  ; represent each process in the list: if the Mth process in the list isn't running, the Mth bit of that number will 
  ; be 0, otherwise 1. To check if process3 is running, for example, you'd do either this:
  ; if ($isbit($isprocess(proc1|proc2|proc3),3)) 
  ; or this:
  ; if ($isprocess(proc1|proc2|proc3) & 4)
  ; (if you don't understand the 2nd example, just use $isbit())
  ; example: if ($isprocess(mirc.exe,1)) { .echo -q $endprocess(mirc.exe,1) }
  if ($isid) {
    if ($2 !isnum 1- || *|* iswm $1) { tokenize 32 $$1 1 }
    var %a = a $+ $ticks, %b = b $+ $ticks, %c = c $+ $ticks
    .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 =" $+ $replace($1",|," OR Name ="),dispatch* %c)
        if ($com(%c)) {
          var %result = 0
          if *|* iswm $1 {
            var %i = 1, %f = $calc(2^ $numtok($1,124) -1)
            while %result != %f && $comval(%c,%i,Name) != $null {
              %result = $biton(%result,$findtok($1,$v1,124))
              inc %i
            }
          }
          elseif if $comval(%c,0) >= $2 {
            %result = 1
          }
          .comclose %c
          return %result
        }
      }
    }
  }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com