![]() |
How to?-Prevent multiple instance of an application
I am writin the app in vb 6.0 and vb.net and want to know how to prevent the application from being opened multiple times on the same computer.
i.e. If the application is already open clicking on the app's icon will only bring the currently open application to the front instead of opening another instance of the app. Thank you for all help given. |
One of the best and easiest way to prevent ur app. from running again when its run , is to create a named Mutex for ur app. then you should check it at the begining of ur app. and if CreateMutex returns the ERROR_ALREADY_EXISTS , then you can be sure that another instance of ur app is running and do whtevere u want ! (Find more info about the "CreateMutex" API in MSDN) :rolleyes:
|
I prefer to use FindWindowEx API to find a similar window
You can find your window properties by SPY++ I think that it's more useful because your process may be killed and the user won't be able to launch your app by the reboot. ba bye |
VB.Net
Code:
'#Zone " Prevent multiple instances " |
hmm, for vb6 it can be done very simply using "App.PrevInstance".
Code:
Private Form_Load( )Code:
Function PrevInstance() As Booleanhttp://www.thescarms.com/dotNet/SingleInstance.asp :D |
if you use MUTEXes as suggested by "just4urim", be sure to release your mutex using a call to releaseMutex() before your program quits
|
Great! Thank you for all the help. I will report back once ive tested it
|
in addition, you'll need to find the previously running app (findwindow), and make it the active window before you exit your program (use win messages). this way, running a 2nd instance of your app brings up the first instance.
|
| All times are GMT +8. The time now is 04:46. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX