Click to See Complete Forum and Search --> : URGENT : Avoiding multiple VB instances ??


M.Anand
March 22nd, 1999, 01:45 AM
How do I prevent running of multiple VB instances ?


Anand

Chris Eastwood
March 22nd, 1999, 02:35 AM
Hi


Do you mean - multiple instances of your VB application, or multiple instances of Visual Basic itself ?


The first one is quite easy, the global App object in VB has a 'PrevInstance' property which lets you know if a previous instance of your application is running, eg.


Sub Main()

If App.PrevInstance Then

'

' Do nothing - or quit, whatever

'

Else

'

' Load the applications main form

'

Load mFrmMain

mFrmMain.Show

End If

End Sub


The second one would require a small vb app to be constantly running in the background, looking at all the top level windows running on the system. This way, you could kill off another instance of VB if it was running (it's a hack, but I don't know of any other way). I saw some code a while back which was designed to stop people running specified programs on their machines (eg. Solitaire, WinMine etc), I'll try and find it if you want.


Regards


Chris Eastwood

Codeguru - the website for developers

http://www.codeguru.com/vb

M.Anand
March 22nd, 1999, 02:57 AM
Hi Chris


I was looking for the first one. Thanks a lot


Anand