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

witch API to use . . . ?

Status
Not open for further replies.

oconv

Programmer
Jan 17, 2002
25
ZA
Ho-ho

I want to prevent someone of starting 2 'instances' of the same progam!
Is there some API(S) that I can use to help me with this (I have been trying to find em for a week now without any luck).
At the moment I am just writing a txt file to the c drive & everytime you start the program it checks if that file is there , but that is a baaaaad idea to do it like that.

Your help will be appretiated hugly !!!!!

thake care

Christiaan
;-)
 
Hi,

You can do it with CreateMutex. It's originally not made for this purpose, but it works very well. When the program starts you should call the CreateMutex function with a specific string for that program. If you try it twice it will fail, thus you know the app has already started. But if the program closes you have to make sure you destroy the mutex with CloseHandle, because the mutex doesn't go away if the program closes.

Good luck
 
just use something like the following...

If App.PrevInstance = True Then Unload Me

or you could put it in a module under sub Main and start your app from there.

If App.PrevInstance = True Then Unload form1
 
cool people , both ways work !!!

thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top