Preventing multiple instances of a VB EXE from running?

I have a VB app that is delivered in the form of an EXE file.  I must prevent the user from running multiple instances of this program.  How do I do this?
david749Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
beckinghConnect With a Mentor Commented:
If App.PrevInstance = True Then
        MsgBox "There are two instances of the application running.  Please click OK, wait 10 seconds, and restart the application.  If the problem persists contact your System Administrator.", vbOKOnly, csMsgBoxTitle
        GoTo exitsub
    End If
0
 
beckinghCommented:
Obviously only the "If App.PrevInstance = True Then" part is relevant :)
0
 
beckinghCommented:
Here's a nice link to a way of launching the app that is already running.

http://vbcode.com/asp/showsn.asp?theID=574
0
 
Richie_SimonettiIT OperationsCommented:
One way to do it is adding a module to your project, create a sub Main procedure and:

Sub Main
    If app.previnstance then
       end
    else
       frmMain.show
    end if
End Sub

Don't forget to swith your start object to the sub main routine going to Project properties menu.
0
All Courses

From novice to tech pro — start learning today.