Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close a window 1

Status
Not open for further replies.

Gazzza

Programmer
Dec 21, 2000
16
0
0
AU
Hi

I want to stop users from having more than one session of an application open. I'm a newbie and have access to the code that was written by someone else. How can I check if the app is already running when someone fires up the exe?

If the app is running I just want to display a msgbox and End. As mentioned I'm new at this so I'm unsure if I would use an api call or there might be a way to do it using code to check. I haven't had much exposure to api yet.

Thanks

Garry
 
check out FindWindow

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

something like this:

"CaptionofProgram" is what you see for the title in the Caption bar -- it must be an exact match.

hWnd = FindWindow(vbNullString, "CaptionofProgram")

If hWnd <> 0 Then

Msgbox &quot;You can't do that.&quot;
End

Endif


 
An easier way would be...

Code:
If App.PrevInstance Then
    MsgBox &quot;Already running&quot;
    end
Else
    MsgBox &quot;Not running&quot;
End If
 
Thanks to both of you I'll be able to use both examples for different things

Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top