Hi all i hope this little code help some people.
This code is to make your program can't open 2 times so when you open your app and try to open it again a msgbox will pop up and wont let you open it again.

Dim CurrentProcesses() As Process
    Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)

        CurrentProcesses = Process.GetProcessesByName _
                           (Process.GetCurrentProcess.ProcessName)
        If CurrentProcesses.GetUpperBound(0) <= 0 Then
            Exit Sub
        End If

        Dim XMsg As String = "Here is what ever you want the msgbox say."
        MessageBox.Show(XMsg, _
                   "Here is the Title of the MsgBox", _
                   MessageBoxButtons.OK, _
                   MessageBoxIcon.Error)
        End
    End Sub

i hope i help you

You can use this too is less complicate.

Dim MymessageBox1
    Dim CurrentProcesses() As Process

Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)

        CurrentProcesses = Process.GetProcessesByName _
                           (Process.GetCurrentProcess.ProcessName)
        If CurrentProcesses.GetUpperBound(0) <= 0 Then
            Exit Sub
        End If
        MymessageBox3 = MsgBox("What ever you want it to say HERE", MsgBoxStyle.Critical, "MsgBox Title HERE")
        End
    End Sub

Edited 7 Years Ago by xfrolox: n/a

Or in your project you can goto the properties window and click the checkbox that says "Make Single Instance application"

\yeah i know
Yup but it wont tell you why you can't open it again,

Anyways both ways works
So...

This question has already been answered. Start a new discussion instead.