Author Topic: Determine if another instance of vs is running?  (Read 5215 times)

dmw

  • Senior Community Member
  • Posts: 145
  • Hero Points: 15
Determine if another instance of vs is running?
« on: July 23, 2006, 03:25:09 pm »
Does anyone know how I can tell, from within a macro, if there is more than one instance of SlickEdit running?

Zak

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Determine if another instance of vs is running?
« Reply #1 on: August 02, 2006, 02:40:32 pm »
One would suspect that since VS supports - or +new at command line startup (to distinguish between cases where an existing instance of VS.EXE should be used or a new instance created) then there may be an elegant way to detect this situation in a macro.  You could search the supplied macro code to see if you can find a way.  However, an inelegant technique that works in Windows XP is as follows:

1. You must have TaskList.EXE in your path... normally this is available only on Windows XP professional, but it can be downloaded for the home version of XP.

2. A batch file similar to the following (e.g. PROCCOUNT.BAT) should be saved in a directory in the the PATH:

@ if exist $out del $out
@ tasklist /FO csv /FI "IMAGENAME eq %1" /nh 1>$out 2>$err
@ set $acc=
@ for /F %%i in ($out) do @set /a $acc=$acc+1
@ if exist $out del $out
@ exit /b %$acc%


3. A macro can be created similar to the following that will run PROCCOUNT and check for instances of running processes by their name:  (Note the special logic to adjust the count of CMD.EXE processes, if that count is necessary, since shell() introduces a new instance of cmd.exe when the count is taken.)

_command proccount() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
   _macro('R',1);

   cmdstring = "proccount ":+arg(1):+'&exit /b %$acc%';
   count = shell(cmdstring,"Q");
   if (stricmp(arg(1),"cmd.exe") == 0)
   {
     count--;
   }
   if (count >= 2)
   {
     messageNwait(count " instances of "arg(1)" are running");
   }
   else if (count == 1)
   {
     messageNwait("only one instance of "arg(1)" is running");
   }
   else
   {
     messageNwait("there are no instances of "arg(1)" running");
   }
}

4. To test the above macro, run PROCCOUNT VS.EXE from the command line in Vslick.

srouleau

  • Community Member
  • Posts: 67
  • Hero Points: 4
Re: Determine if another instance of vs is running?
« Reply #2 on: August 19, 2006, 12:35:09 pm »
Hey, wow, gee wheeze, didn't know about the +new option.  Doh!  I'd been stuck in single-instances-of-VS for so long now, I'd forgotten life without it.

Wow!

Thanks :)

Steph

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Determine if another instance of vs is running?
« Reply #3 on: August 19, 2006, 12:46:10 pm »
... didn't know about the +new option.

Be aware that if you have more than one instance of SlickEdit running, you won't save any config information (vslick.sta), except for the last instance of SlickEdit that gets closed.  You will be prompted : "Unable to save configuration.  Do you want to exit anyway?" 
You can avod the prompt by using 'fexit' on SlickEdit command line.