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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow only one instance of an application to run? 4

Status
Not open for further replies.

vbkris

Programmer
Jan 20, 2003
5,994
0
0
IN
I have created an exe using VB. i want only one instance of the application to run at a given point. but by default all exe's created in VB can always have more than one instance. i.e
double click on the exe file an instance is created.
while the exe is running if i double click on the exe file again a new instance is created. i want the original instance to automatically popup (like dreamweaver, adobe)
 
no kidding, app.previnstance! I never knew that, if it works, you're getting a star and I look like a goofball! ;) Tuna - It's fat free until you add the Mayo!
 
Well folks, it just goes to show that simple is so very, very often overlooked... call me the king of overkill, and here's your star PetMel! Tuna - It's fat free until you add the Mayo!
 
The One Good thing about VB that is bad...
It is SO simple to to most things... they are often overlooked...
Then After writing code for a day or 2, to accomplish a task...
Someone throughs out a line or 2 of code that does the eqivalent of the modual or 2 you have been working on... (lil exageration there)
...But you still gotta luv VB ;-)
It beats the **** out of VC++ [hammer] Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
previnstance solved one problem. but then how do i activate the old instance. right now only a message box can be given but i want the older instance to be activated.
 
VBKRIS,

I think I can help you with the whole thing here.

I have a Sub that I called ALREADYRUNNING (it's below). I use an MDIForm for my main form & it gives me no problems. I call it pretty early in my startup module to keep it fom doing too much before going to the previous instance.

The thing is, you need to know the caption of your Main Form.



Public Sub AlreadyRunning()

' This sub will determine if a Windows App. containing the string (strWindowTitle)
' in the windows title bar is already running on the machine. This is to prevent the app from
' being run more than once on the machine at any time. If the app is already running, this fuction
' will activate that instance of the app and shut down the second attempt of the app.


Dim strSaveTitle As String

If App.PrevInstance Then

strSaveTitle = "CAPTION OF YOUR MAIN FORM" ' save the name of the app to a string

' rename this instance of the app to avoid an ambiguous reference of the titles between the apps
App.Title = "Duplicate instance of..........." & strSaveTitle

' activate the first instance of the app
AppActivate strSaveTitle

' send keystrokes to the first instance to restore its window state
SendKeys "% R {ENTER}", True

' end the second instance.
End

End If

End Sub






Good Luck. I Hope it helps

John [spidey] [americanflag] [unclesam]
 
thanks guys i have managed to overcomt the problem. but does any one know how to create a horizontal scrollbar in visual basic?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top