Not more than one instance per user, But allow on different users

  • Thread starter Thread starter André Nogueira
  • Start date Start date
A

André Nogueira

Hi there guys
I want my program not to allow more than one instance per user.
Now I have this code


CODE
Dim Processos() As Process
Processos = Process.GetProcessesByName("Taskfind")
If Processos.Length > 1 Then
NotifyIcon1.Visible = False
End
End If


The problem is that if Fast User Switching is enabled on XP and one user is
running my program, all the other users of that machine can't run the
program.
What can I do to ensure that no other instance of my program is running, but
only on the current user?
Thank you in advance!

Andre Nogueira
 
Use this function:

Private Function PrevInstance() As Boolean
If
UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function

In form load:

If PreviousExistance() = True Then
MessageBox.Show("Application is already running. Press OK to exit")
End
End If

If you use 'Application.Exit()' after showing the message box then the form
is briefly shown, but with 'End' it is halted immediately & the form is never
shown.

I hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top