mIRC Homepage
Posted By: pball Check if mirc is already running - 18/03/11 03:38 PM
It'd be nice if mirc could check if there is another instance of mirc running from the same settings. Since it's always a pain when you accidentally open your mirc twice and all protection scripts like ghost and such get into a loop between the two mircs.

My idea is to just have mirc say "Another instance of mirc is running from this location." then have an exit or continue button
Posted By: westor Re: Check if mirc is already running - 18/03/11 07:07 PM
Good idea, and an option in the settings like "Check if mirc is running on start" including an enable/disable alias like (/checkmirc on/off) will be also good.
Posted By: argv0 Re: Check if mirc is already running - 18/03/11 10:43 PM
+1. I use a script to check how many mIRC instances are running prior to running my main ON START event, so that I don't launch multiple connections to the same network by accident.
Posted By: Aha2Y Re: Check if mirc is already running - 22/03/11 09:01 PM
Nice idea.

+1
Posted By: pball Re: Check if mirc is already running - 24/03/11 10:19 PM
Yeah i'm thinking about scripting something for now, but a built in feature would probably be more reliable.

Mind sharing how you are doing it? I was thinking check if a file exists before doing anything, if it does stop and close. That should work unless mirc crashes and is unable to delete the lock file when it closes.

[update]
I made a little script using the lock file idea.

Code:
on *:load:{ write running.lock | .reload -rs1 $script }
on *:unload: if ($isfile(running.lock)) remove running.lock
on *:start:{ if ($isfile(running.lock)) { set -e %er 1 | exit } | else write running.lock }
on *:exit: if (!%er) remove running.lock


It reloads it self as the 1st script since I know I have scripts that do connection stuff and it should run first. It works better than I hoped, but I do get the vars.ini file has changed popup since I do set a var in the check.
Posted By: FroggieDaFrog Re: Check if mirc is already running - 24/03/11 11:50 PM
I do something similar, except i check if the mirc.ini is being used:
Code:
alias -l mFile { return "C:\mircini.txt" }
alias -l mCheck {
  if ($read($mFile,snp,$mIRCIni)) {
    var %l $v1
    if ($1 == -s) { exit }
    else {
      write -dl $+ %l $mFile 
      if (!$read($mFile,np,1)) { .remove $mFile }
    }
  }
  elseif ($1 == -s) {
    write $mFile $mIRCIni
  }
}

on *:Start:{
  if ($script(1) != $script) { .reload -rs1 $script }
  mCheck -s
}
on *:Unload:{ mCheck }
on *:Exit:{ mCheck }
Posted By: Jinx_Dojo Re: Check if mirc is already running - 10/04/11 05:41 PM
I, too, would like to see this. I also try to use a script to keep track of mIRC's current instance, but computer crashes easily yield incorrect results. It would be very helpful if mIRC could tell me which instance it is via an identifier ("$mIRCInstance" perhaps).

Of course, the behavior of such an item would need to be determined: upon opening two instances, and closing the first, then opening a new instance, does the new instance receive a new ID number or revert to the first?

In this case, two identifiers may be appropriate: one to provide a unique ID (which is reset only upon system boot), and another to indicate how many instances were running at the time of mIRC's launch. (This seems somewhat parallel to the function of scid/scon.)

Maybe this isn't mIRC's job, but it would certainly make things easier.
Posted By: Chessnut Re: Check if mirc is already running - 11/04/11 03:36 AM
A better workaround that doesn't involve creating a special file or something like that is:

Code:
alias numMirc {
  .comopen numMirc1 WbemScripting.SWbemLocator
  if ($com(numMirc1)) .comclose numMirc1 $com(numMirc1,ConnectServer,3,dispatch* numMirc2)
  if ($com(numMirc2)) .comclose numMirc2 $com(numMirc2,ExecQuery,3,bstr, $& 
    SELECT * FROM Win32_Process WHERE Name = "mirc.exe" $&
    ,dispatch* numMirc3)
  if ($com(numMirc3)) {
    var %total $comval(numMirc3,0)
    .comclose numMirc3
    return %total
  }

  :error
  if ($com(numMirc1)) .comclose numMirc1
  if ($com(numMirc2)) .comclose numMirc2
  if ($com(numMirc3)) .comclose numMirc3
  return -1
}


I'm not sure what you mean by "running from the same settings". If you meant that you wanted to return only the number of mIRCs running that use the same .exe, change:

Quote:
SELECT * FROM Win32_Process WHERE Name = "mirc.exe"


to

Quote:
SELECT * FROM Win32_Process WHERE ExecutablePath = $qt($replace($mircexe,\,\\))


I agree that this would be a nice feature to have implemented anyway, but the above script should work just as well!
Posted By: drum Re: Check if mirc is already running - 11/04/11 05:09 AM
Originally Posted By: Chessnut
I'm not sure what you mean by "running from the same settings".


He means sessions that use the same mirc.ini configuration file, basically. You might want to be able to run one copy of mIRC with mirc1.ini and a second copy of mIRC with mirc2.ini, but not be able to run two copies of mIRC with mirc1.ini at the same time. Unfortunately this looks to be a bit harder to do with your method (you'd have to compare $mircini from each session).

I think a built-in method of preventing multiple sessions would work best for this. Not because it's impossible to do with scripting, but because it would be useful enough, IMO, to build into the program directly.
Posted By: pball Re: Check if mirc is already running - 11/04/11 04:01 PM
drum you are correct about what I mean about a single instance of mirc running.

I still believe a built in method would be best but Chessnut has posted something that seems like the best alternative. I have a little alias that returns if a given program is running, but the way it's made isn't helpful since it just gives true or false. However that code above is quite perfect since it can check if the current mirc exe is being ran twice. Thanks Chessnut

p.s. i only ever run 1 mirc exe with 1 mirc.ini so i don't have to bother checking anything more than if the mirc exe is already running.

edit:
posting the final script, which is 99% Chessnut's and 1% on start event ^_^

Code:
on *:start: if ($numMirc > 1) exit

alias numMirc {
  .comopen numMirc1 WbemScripting.SWbemLocator
  if ($com(numMirc1)) .comclose numMirc1 $com(numMirc1,ConnectServer,3,dispatch* numMirc2)
  if ($com(numMirc2)) .comclose numMirc2 $com(numMirc2,ExecQuery,3,bstr, $& 
    SELECT * FROM Win32_Process WHERE ExecutablePath = $qt($replace($mircexe,\,\\)) $&
    ,dispatch* numMirc3)
  if ($com(numMirc3)) {
    var %total $comval(numMirc3,0)
    .comclose numMirc3
    return %total
  }

  :error
  if ($com(numMirc1)) .comclose numMirc1
  if ($com(numMirc2)) .comclose numMirc2
  if ($com(numMirc3)) .comclose numMirc3
  return -1
}
Posted By: argv0 Re: Check if mirc is already running - 13/04/11 12:29 AM
In fact this is the script I use to keep my instances in check.

Rather than exiting, I use the check to avoid any initialization:

Code:
on *:START: { 
  if ($count_processes(mirc%.exe) <= 1) {
    server irc.server.com ...
    server irc.server2.com
  }
}


This way I could start multiple instances of mIRC but without automatically creating multiple connections. Very useful for debugging, especially when testing different versions of the client.

In that sense, it would be equally useful for mIRC to expose a builtin identifier to give us the number of running mIRC processes so we can use this check in our scripts.
Posted By: KindOne Re: Check if mirc is already running - 13/04/11 09:15 AM
This might not be reliant, but you could set mIRC to require a password on Startup.

Tools -> Options -> Other -> Lock

I have this set so that I do not accidentally open another instance of mIRC, and to also keep mIRC "locked down" while I am away from my computer.
© mIRC Discussion Forums