Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Run Program Once

Hi,
How can I make sure that my application can run only once if it's already in use? (meaning: if the user already start using the application, and the application was minimized, then another user try to run the application again, the last user must received either error message or the application become maximized).
Please help!
Thank you,
[359 byte] By [moe188] at [2007-11-11 6:59:04]
# 1 Re: Run Program Once
http://www.vbexplorer.com/VBExplorer/tips/src03.htm
Phil Weber at 2007-11-11 17:27:38 >
# 2 Re: Run Program Once
Well I tried but I get the following message:
Run-time error '5'
Invalid procedur call or argument

Can you help?
moe188 at 2007-11-11 17:28:38 >
# 3 Re: Run Program Once
Not unless you tell us on which line of code the error occurs.
Phil Weber at 2007-11-11 17:29:38 >
# 4 Re: Run Program Once
the message appear once I minimized the program, and I tried to run the program again, that's when I get the message.
Thank you,
moe188 at 2007-11-11 17:30:44 >
# 5 Re: Run Program Once
"Line of code." Which line of code causes the error?
Phil Weber at 2007-11-11 17:31:42 >
# 6 Re: Run Program Once
When they try to open the same application put this into the form_load()

Private Sub Form_Load()
If App.PrevInstance = True Then 'Application is already running
MsgBox "Application is already Running, Please exit before opening again!", VbCritical
End If
End Sub
XRsTX at 2007-11-11 17:32:41 >
# 7 Re: Run Program Once
I am a little confused. In each reply the PrevInstance Property is discussed.
In your post you talk about one person has the program open and minimizes it, then another person opens the program. Is the second person opening the program on the same pc or is this a program stored on a network drive and two different people on two different pc's start the program from the network drive? If it is a program stored on a network drive and two people try to run it on different pc's, the PrevInstance Property will not work.
jnesbett at 2007-11-11 17:33:45 >