mIRC Home    About    Download    Register    News    Help

Print Thread
#225719 08/09/10 04:16 PM
Joined: Sep 2007
Posts: 202
F
firefox Offline OP
Fjord artisan
OP Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
if I run a program with

/run program.exe $1 $2

can I then have to so the next time I call the alias with the /run command inside it is checks to see if program.exe is running and if it is waits to call the alias until program.exe is no longer running?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
It is possible, but you would need something to check the processes that are running. This, I believe, would require usage of $com or a custom DLL.

Joined: Sep 2007
Posts: 202
F
firefox Offline OP
Fjord artisan
OP Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
thanks

anyone know how to do this using $com?

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
I once used this code (a modified snippet by ...er, I forgot frown ):
Code:
alias isrun {
  if (($isid) && ($1 != $null)) {
    if ($com(isrun_a)) { comclose isrun_a }
    if ($com(isrun_b)) { comclose isrun_b }
    .comopen isrun_a WbemScripting.SWbemLocator
    if (!$com(isrun_a)) { return }
    .comclose isrun_a $com(isrun_a,ConnectServer,3,dispatch* isrun_b)
    if (!$com(isrun_b)) { return }
    .comclose isrun_b $com(isrun_b,ExecQuery,3,string,SELECT ProcessId FROM Win32_Process WHERE Name = $qt($1) $+ ,dispatch* isrun_a)
    if (!$com(isrun_a)) { return }
    noop $com(isrun_a,Count,3)
    var %return = $iif(($com(isrun_a).result),$true,$false)
    .comclose isrun_a
    return %return
  }
}
Example:
Code:
//echo -ag $isrun(cmd.exe) | run cmd.exe | echo -a $isrun(cmd.exe)



For a "wait till process x is no longer running", you could do something like:
Code:
alias delayrun {
  ; possible /run switches
  var %switches = $iif(($left($$1,1) == -),$1)
  if (%switches) { tokenize 32 $2- }

  ; possibly quoted process (file name)
  var %proc = $iif($regex($1-,/^"([^"]+)"/),$regml(1),$1)

  ; process not running: issue /run command
  if (!$isrun(%proc)) { !run %switches $1- }

  ; process currently running: start retry timer (500 ms delay)
  else { $+(.timer.delayrun.,%proc,$ticks) -mdo 1 500 delayrun $safe2(%switches $1-) }
}

; prevent evaluation of the command passed in the timer
alias -l safe2 { bset -t &a 1 $1 | return $!regsubex(safe2, $bvar(&a,1-) ,/(\d+)(?: |$)/g,$chr(\1)) }

Example:
Code:
//var %c = cmd.exe /q /c ipconfig /all | run %c | run %c
(two instances of the command shell should pop up "together")
vs.
Code:
//var %c = cmd.exe /q /c ipconfig /all | delayrun %c | delayrun %c
(the second window should pop up after the first closed)

Note that the more /delayrun commands you queue, the more overhead the individual timers will create. If you want to queue *lots* of commands for some process, better use one timer per process name that if the process closed is calling some /next.run alias (which in turn manages your queue) or sends a /signal or the like.

Joined: Jul 2006
Posts: 4,153
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,153
Just a little note about the safe alias, I reported that you need to use bset -ct or bunset after /bset to clear the bvar before using it because it could be used more than one time in the same scope, and that would be a problem.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard