Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake sure only one instance of a program can run at one time on a computer
DescriptionThis example shows how to make sure only one instance of a program can run at one time on a computer in Visual Basic 6. When the program starts, it checks App.PrevInstance to see if an instance of the program is already running and exits if one is.
Keywordsone instance, instance, DDE
CategoriesSoftware Engineering, Windows
 
When the program starts, it checks App.PrevInstance to see if an instance of the program is already running. If one is, the program says so, uses AppActivate to activate that instance, and exits.
 
Private Sub Form_Load()
Dim cap As String

    If App.PrevInstance Then
        ' Tell the user that another instance is already
        ' running.
        MsgBox "Another instance of the program is already " & _
            "running", vbCritical

        ' Activate the other instance.
        cap = Me.Caption
        Me.Caption = ""
        AppActivate cap

        ' Exit.
        Unload Me
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated