How Does Make Sure Only One Instance of an Application Runs? (1 Viewer)

llyal

Registered User.
Local time
Today, 21:13
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
 

Alexandre

Registered User.
Local time
Tomorrow, 03:13
Joined
Feb 22, 2001
Messages
794
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
 

Never4Get

Registered User.
Local time
Today, 21:13
Joined
Aug 24, 2001
Messages
14
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...
 

llyal

Registered User.
Local time
Today, 21:13
Joined
Feb 1, 2000
Messages
72
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
 

llyal

Registered User.
Local time
Today, 21:13
Joined
Feb 1, 2000
Messages
72
To All,

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

Thanks for the help!

--llyal
 

arvindn

Registered User.
Local time
Tomorrow, 01:43
Joined
Oct 1, 2003
Messages
99
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

Top Bottom