Many programs can only be run one instance at a time. (for example, MSN or AIM messengers) How do they do this, and how can I make my program be like this too?
Printable View
Many programs can only be run one instance at a time. (for example, MSN or AIM messengers) How do they do this, and how can I make my program be like this too?
VB Code:
Private Sub Form_Load() If App.PrevInstance = True Then Msgbox "Application Already Running" Unload Me End Sub
VB Code:
If App.PrevInstance = True Then MsgBox "This program is already running !", vbCritical, "Fallout[]" End End if
Here's a tip: if this program is security intensive, then App.PrevInstance will not do a good job. All the person has to do to override App.PrevInstance is change the file's name to something else and run it again :P.
Use the FindWindow API to get the hWnd of the previous instance using the Caption of the main form. If the hWnd is found, then shut down the current instance. This method is a bit harder to override because you would need to hex-edit the program in order to change the caption of the main form.
Wow, thank you all.
Take a look at this and in the Frequently Asked Question link below my sig. :)