prevent another instance of exe to execute

zachvaldez
zachvaldez used Ask the Experts™
on
I build a vb.net app exe and save it in the network.
If a user has already launch the exe, is it possible to suppress the ability to launch another instance of the exe if it already running so to prevent multiple exe  hanging in the registry.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Commented:
If your application starts in a form (not a Main method), you can simply open the project's Properties window (Project menu), activate the Application tab, then Enable application framework and finally check Make single instance application.

If your application is more complex and/or need to start in a Main method, then use the following code at the beginning of Main:

Public Sub Main()

    If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Count > 1 Then
        MessageBox.Show("Use already running copy of the application.")
        Application.Exit()
End If

Open in new window

Author

Commented:
thanks,
that worked. I did'nt know that..

Author

Commented:
I did it in design because I start with the form

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial