Re: Checking for another instance of an application

From: Björn Holmgren (bjohol_at_hotmail.com)
Date: 04/01/04


Date: Thu, 1 Apr 2004 12:51:45 +0200

The problem with App.Previnstance is that it will only return true if you
start the same exe twice from the exact same location. If the exe resides in
different locations or if it's started using a different path notation,
previnstance will return false.

Try this:

1) Put your exe file on a network share
2) Map a drive to the share
3) Start the app using the mapped path (ie H:\MyApp.exe)
4) Now start another instance using the UNC path (ie
\\MyServer\MyShare\MyApp.exe)

App.Previnstance will return False because the second app is started using a
"different" path.

Personally, I prefer using a named mutex (see BeastFish's reply), but
needless to say, you must come up with a unique name. Generating a GUID for
your app and using that to name the mutex is a good idea.

One problem with the mutex approach is that you need to write code to bypass
the instance checking when run from within the IDE. The reason for this is
that the mutex isn't removed until VB6.EXE is terminated.

--
Björn Holmgren
Guide Konsult AB
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:#TRt#W0FEHA.2976@TK2MSFTNGP10.phx.gbl...
> The basics.... check if App.PrevInstance = True. If so, there's another
> instance. If that's not enough, there are tons of ways to do it but all
> involve pages of API calls.
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep all discussions in the groups..
> "Gary T. H. Novosel" <novosel-g@northnet.org> wrote in message
> news:uVIK8%23zFEHA.2404@TK2MSFTNGP11.phx.gbl...
> How do I go about seeing if there is another instance of my application
> already running on a system? I want to limit the application to run only a
> single instance at a time.
>
> Thanks.
>
> Gary
>
> --
> Gary Novosel
>
> The are 10 types of people in the world, those who understand binary and
> those who do not.
>
>


Relevant Pages

  • Re: Synchronised Read/Write Problem
    ... A mutex will help you if you had a true Singleton object. ... Sam Santiago ... >> access to this external EXE behave in a single threaded manner. ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: Running processes
    ... a win32 console application is already runing or not from another win32 ... console application.I need only one copy of exe has to run(for that i ... the return value is a handle to the mutex object. ... If the function fails, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: - How Do You Check for Multiple Copies of An App?
    ... but what PDF are you looking at? ... I, of course, have your excellent plugin and will try to use your Mutex in 5.5 ... app, but first let me make sure it can do what I want. ... detect a second copy of my app launched from the same exe, ...
    (comp.lang.basic.realbasic)
  • Re: How to allow a specific number of Instances of my app?
    ... copy of the EXE, rename it or put it into a different folder and run the EXE ... make a mutex that is not dependant on the file name. ... another terminal server session, or a second session in XP fast user ...
    (microsoft.public.vb.general.discussion)
  • Re: Right-Click send to
    ... You could use a mutex. ... to see if there's already an instance running of the exe. ... >> I've written an instant message application that has the ability to send ... > To" menu, that will either lauch the application if it's not running, or ...
    (microsoft.public.dotnet.languages.csharp)

Loading