Results 1 to 5 of 5

Thread: check if application duplicate

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    40

    check if application duplicate

    hi again,
    i know i've been posting alot today, but i am close to finishing my first .net application so i need to put in a few final touches.
    how can i allow windows to run only one 'instance' of my program? that is, while program running, user cannot execute exe file of the program....

    thanks

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try searching for 'single instance' on this forums. This question comes up frequently. In fact you should always try a search before posting if you want to save sometime. Lastly if you find multiple examples pick the one that uses a Mutex it'll be faster. In fact here I'll do the search for ya: http://www.vbforums.com/search.php?s...der=descending

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    40
    lol thanks

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Talking Yes , always do a search boy

    This was copied from VBCodeBook , you know that guys

    VB Code:
    1. Check for multiple instances of a program and ask the user if he / she wants to run another copy.
    2.    
    3.     'Create a new instance of your main form
    4.     Dim MainForm As New Form1()
    5.  
    6.     Private Sub MultiCheck()
    7.         'Get number of processes of you program
    8.         If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
    9.             'Ask user if they want to run another copy
    10.         If MessageBox.Show("There is already a copy of this program." & vbCrLf _
    11.             & "Do you want to launch another?.", _
    12.             "Launch another copy of this program?", _
    13.             MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
    14.             MessageBoxDefaultButton.Button1) = DialogResult.No Then
    15.             'If no, then exit the new instance of the program
    16.                 Application.Exit()
    17.                 Exit Sub
    18.             Else
    19.             'Else run the new program
    20.                 MainForm.ShowDialog()
    21.                 Exit Sub
    22.             End If
    23.         End If
    24.         'If this is the only one, run it!
    25.         MainForm.ShowDialog()
    26.     End Sub

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I used to use that same process but the Mutex way is much faster, like 10 times faster.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width