tags:

views:

88

answers:

3

I have a VB.NET program. In proerties/Application I checked Make a Single Instance Application. But it still allows someone from opening the program while already opened. How can I prevent this?

A: 

When you select Make Single Instance Application, starting a new copy of the program will automatically switch to the existing copy.

You can customize this behavior in the Application class.

SLaks
A: 

The short answer is you can't. VB does some tricks behind the scenes to help you accomplish this since it's a common business requirement. However anything you create that is actually exclusive opens you to a denial of service attack by someone else maliciously creating/holding that resource and denying it to you.

Common ways are creating a well known mutex/semaphore/named pipe/something similar and if it already exists, exiting the instance just launched. There just isn't a secure way of doing what you want to do.

No Refunds No Returns
+1  A: 

The commonest way to do this is to implement a mutex, however, I will point you to an article or two, here, and here on CodeProject.

Hope this helps, Best regards, Tom.

tommieb75