chee68
asked on
How To Detect VB Running Application
Hi,
I have write a VB program and compiled to executable file. I want to prevent user launch the program/application more than once. If the program already launch, and user try to launch it again, i would like the program to activate the exsiting program automatically. Could it be done? How?
Thanks
chee
I have write a VB program and compiled to executable file. I want to prevent user launch the program/application more than once. If the program already launch, and user try to launch it again, i would like the program to activate the exsiting program automatically. Could it be done? How?
Thanks
chee
You can use App.PrevInstance to see if the program is already running. If it is you can use close the new program. How to activate the existing app.. I don't know.. maybe by searching all the windows for the one with the right caption, that would be the most simple answer but that depends on what caption you have on ya main form?
Put the following code in your start-up in your start-up object, e.g. Sub Main:
Sub Main()
If App.PrevInstance Then
AppActivate "My Application"
End
End If
....
End Sub
Note: "M Application" is the caption of your application.
Sub Main()
If App.PrevInstance Then
AppActivate "My Application"
End
End If
....
End Sub
Note: "M Application" is the caption of your application.
Ok, a guy walks into a bar and order 21 shots of tequila then he goes home. He returns to the bar the next day and the bartender says "Hey wernt you that guy who order 21 shots of tequila". The man responded "why yes". The bartender asked "Well what hapend when you went home?". The man said "I blew chunks". The bartender said "Well of course after 21 shots of tequila". The man said "You dont understand chunks is my dog".
ASKER
SLE, VBMaster,
I'll try out your suggestion.
Thanks
chee
I'll try out your suggestion.
Thanks
chee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I guess I didn't make it overly clear above...this is one way the Microsoft is another.
' See if there is already and instance.
If App.PrevInstance Then
' Activate the previous instance
AppActivate App.Title
' Send a key (here SHIFT-key) to set the
' form from the previous instance to the
' top of the screen.
SendKeys "+", True
' Terminate the new instance
Unload Me
End If
' See if there is already and instance.
If App.PrevInstance Then
' Activate the previous instance
AppActivate App.Title
' Send a key (here SHIFT-key) to set the
' form from the previous instance to the
' top of the screen.
SendKeys "+", True
' Terminate the new instance
Unload Me
End If
Juilette,
"both open"? Did you spot the "End"? It works fine, I believe you're making things far too complicated.
You *are* right though about one thing: if the app is minimized it won't be set to the foreground (I did not make a call to SetForeGroundWindow).
;-)
"both open"? Did you spot the "End"? It works fine, I believe you're making things far too complicated.
You *are* right though about one thing: if the app is minimized it won't be set to the foreground (I did not make a call to SetForeGroundWindow).
;-)
Ooops...your're right...I didn't see it.
As far as too complicated...that's the MS version and I would think it covers all bases.
I bow out, humbly....your's will work, not as complete as the MS version, but it will work.
Wayne
As far as too complicated...that's the MS version and I would think it covers all bases.
I bow out, humbly....your's will work, not as complete as the MS version, but it will work.
Wayne