You are referring to Single Instancing and since your tag reads VB.Net, it's a whole lot easier,
Go to project setting by
-
Right Click on your project name in the properties explorer and select Properties, it's the last item in the context or
- Click on Project on the menu bar and select the last item in the drop-down, should be 'Your AppName'
Properties or
- Press
Alt + P + P.
Now, this takes you to your project properties and in the Application tab under
Windows Application Framework properties check/tick
'Make single instance application'
To make your application show a message when another instance is started, just scroll down on the same page you're on and click on the button
'View Application Events' on the bottom right... This takes you to another page add this code below to the page.
Namespace My
Partial Friend Class MyApplication
Private Sub MyApplication_StartupNextInstance(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
MessageBox.Show("An instance of this application is already running!");
End Sub
End Class
End Namespace