How Does Make Sure Only One Instance of an Application Runs?

llyal

Registered User.
Local time
Today, 14:41
Joined
Feb 1, 2000
Messages
72
How Does Make Sure Only One Instance of an Application Runs?

Hi,

I have an application and would like to prevent users from opening more than one instance of it; How does one do this? I don't need any code, just the general idea of how to do it;

Thank you!

--llyal
 
Using API you could go through all windows and detect if a window's caption is equal to the application title. I am sur I have seen sample code for that somewhere. I could try to find it if you like.


Alex
 
Try using the following API-functions:
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal Hwnd As Long, ByVal lpClassname As String, ByVal nMaxCount As Long) As Long
Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" _
() As Long
Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" _
(ByVal Hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal Hwnd As Long, ByVal lpString As String, ByVal aint As Long) As Long

If you need any more help, contact me any time...
 
To All,

I found an easier solution; in the load event of the VB app, use this:

If App.PrevInstance = True Then
End
End If

Thanks for the help!

--Llyal
 
To All,

Actually my solution did involve the API window libs to do what I wanted;

Thanks for the help!

--llyal
 
I am also looking to limit my application to a single instance. In your second last reply u said that u had a very simple solution

if application.previnstance....

Then u wrote that u had to use API. Does the method of using application.previnstance not work?
 

Users who are viewing this thread

Back
Top Bottom