Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
Dear Programmers ,

I want my exe programmer to run syste, but only one process should run per user

C#
{
            Process curr = Process.GetCurrentProcess();
            Process[] procs = Process.GetProcessesByName(curr.ProcessName);
            foreach (Process p in procs)
            {
                if ((p.Id != curr.Id ) && (p.SessionId != curr.SessionId) &&
                    (p.MainModule.FileName == curr.MainModule.FileName))
                    return p;
            }
            return null;
        }


e.g

1) if A has start my exe and application is running now under his name and again if he tried to do that it should not run : --this i am able to achieve from above code

2) But if b start exe it should allow him to run process : can you help me with this
Posted

1 solution

Not sure if I understand the question correctly, but if you want to restrict only the current session, should the condition be
C#
...
if ((p.Id != curr.Id ) && (p.SessionId == curr.SessionId) &&
                    (p.MainModule.FileName == curr.MainModule.FileName))
...
 
Share this answer
 
Comments
Vipul Ghadg 13-Aug-15 1:13am    
Thank you so much, it was silly of me that i asked, but thanks you pointed out otherwise i ws heating my head in lots of other options
Wendelius 13-Aug-15 2:42am    
Glad to be of service :)

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