Board index » Visual Studio » Not more than one instance per user, But allow on different users
|
peggold
|
|
peggold
|
Not more than one instance per user, But allow on different users
Visual Studio226
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 - |
| Mike
Registered User |
Sun Jan 30 11:24:22 CST 2005
Re:Not more than one instance per user, But allow on different users
On approach is to use a Mutex.
See: codeproject.com/vb/net/sing_inistan.asp">codeproject.com/vb/net/sing_inistan.asp You must establish a Mutex for each user. -- Mike Mike McIntyre Visual Basic MVP www.getdotnetcode.com "André Nogueira" <anog@netcabo.pt.NOSPAM>wrote in message QuoteHi there guys - |
| Crouchie1998
Registered User |
Sun Jan 30 19:19:01 CST 2005
Re:Not more than one instance per user, But allow on different users
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 "Mike McIntyre [MVP]" wrote: QuoteOn approach is to use a Mutex. |
