mIRC Home    About    Download    Register    News    Help

Print Thread
Check if mirc is already running #230697 18/03/11 03:38 PM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
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


http://scripting.pball.win
My personal site with some scripts I've released.
Re: Check if mirc is already running [Re: pball] #230713 18/03/11 07:07 PM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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.

Re: Check if mirc is already running [Re: pball] #230727 18/03/11 10:43 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
+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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Check if mirc is already running [Re: pball] #230841 22/03/11 09:01 PM
Joined: Mar 2011
Posts: 2
A
Aha2Y Offline
Bowl of petunias
Offline
Bowl of petunias
A
Joined: Mar 2011
Posts: 2
Nice idea.

+1

Re: Check if mirc is already running [Re: argv0] #230915 24/03/11 10:19 PM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
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.

Last edited by pball; 24/03/11 11:10 PM.

http://scripting.pball.win
My personal site with some scripts I've released.
Re: Check if mirc is already running [Re: pball] #230918 24/03/11 11:50 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
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 }


I am SReject
My Stuff
Re: Check if mirc is already running [Re: FroggieDaFrog] #231276 10/04/11 05:41 PM
Joined: Feb 2003
Posts: 31
J
Jinx_Dojo Offline
Ameglian cow
Offline
Ameglian cow
J
Joined: Feb 2003
Posts: 31
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.

Re: Check if mirc is already running [Re: pball] #231294 11/04/11 03:36 AM
Joined: May 2007
Posts: 37
C
Chessnut Offline
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 37
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!

Last edited by Chessnut; 11/04/11 03:38 AM.
Re: Check if mirc is already running [Re: Chessnut] #231295 11/04/11 05:09 AM
Joined: Dec 2002
Posts: 344
D
drum Offline
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
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.

Re: Check if mirc is already running [Re: drum] #231303 11/04/11 04:01 PM
Joined: Nov 2009
Posts: 295
P
pball Offline OP
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
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
}

Last edited by pball; 11/04/11 04:14 PM.

http://scripting.pball.win
My personal site with some scripts I've released.
Re: Check if mirc is already running [Re: pball] #231330 13/04/11 12:29 AM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Check if mirc is already running [Re: pball] #231335 13/04/11 09:15 AM
Joined: Feb 2011
Posts: 366
K
KindOne Offline
Pan-dimensional mouse
Offline
Pan-dimensional mouse
K
Joined: Feb 2011
Posts: 366
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.


irc.swiftirc.net #msl (mIRC Scripting Language)