Solved

Preventing multiple instances of a VB EXE from running?

Posted on 2001-06-13
4
248 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:david749
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
beckingh earned 50 total points
ID: 6185837
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
 
LVL 4

Expert Comment

by:beckingh
ID: 6185844
Obviously only the "If App.PrevInstance = True Then" part is relevant :)
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6185858
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6187559
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 62
VBA/SQL - Connect to SQL server and pull data 4 110
Sending a email via excel using vba 6 82
IF ELSE Statement in Excel Macro VBA 16 64
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question