Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to restrict the application start up.
Already I have restricted by Using this Code.

p = Process.GetProcessesByName("application.exe")
       If p.Count > 1 Then
          XtraMessageBox.Show("Application" & " is already running", "Meg", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           End
       End If


It works fine.

But if I have two user in a system it throws already application is running.
so I have to check the user name of the computer too in the validation .
Application should open in the other user. if a user tries to open double time it has to be restricted.

how to overcome this issue??



Regards,
Palraj M

What I have tried:

p = Process.GetProcessesByName("application.exe")
       If p.Count > 1 Then
          XtraMessageBox.Show("Application" & " is already running", "Meg", MessageBoxButtons.OK, MessageBoxIcon.Warning)
           End
       End If
Posted
Updated 30-Aug-16 5:22am

1 solution

I'm pretty sure this would be a time to use Mutex:

The Misunderstood Mutex[^]

A Mutex is "kinda" like a "lock", but it exists across all .net processes. You can create a Mutex for the user as in the examples in the link above, or set it globally for the terminal service machine so all instances for all users can see it.

You want the first option. If the Mutex is not global then only each user can see their own. Make sure the program checks for the mutex on startup. If it exists: "Already Running", if not: Create mutex and start

Hope that helps
Andy
 
Share this answer
 
Comments
Richard Deeming 30-Aug-16 15:09pm    
A mutex exists across all processes, not just .NET ones. :)
Andy Lanng 31-Aug-16 3:59am    
ooh. I just googled the problem. I should have stated that this was actually the first I'd ever heard of mutex ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900