Answered Ways to show what application are running ?

Matthew Rodwell

New member
Joined
Aug 13, 2020
Messages
3
Programming Experience
Beginner
Afternoon, i am creating an app for our Admins. and i want it to show what app is used by what users. So for example i want to check on a server which users have say word open. Firstly is this possible in C# or is there a better way to do this. I want to be able to show them incase there are any issues with tthat software

thank you...be kind
 
I updated post #2 while you were replying.
 
Yea it's possible. Of course it is, if it can be done in task manager it can be done in your own app.

Depending on what you're trying to do, perhaps a mutex would be a better way to go? Going the way of Mutex you could grant access to a process. You can use this pseudo code as your example to get started :
C#:
        public string GetOwnerOfProcess(string nameOfProcess)
        {
            using (Mutex mutex = new Mutex(false, nameOfProcess, out bool gotAccess))
            {
                try
                {
                    if (!mutex.WaitOne(0, false))
                    {
                        /* Already running */
                        return null;
                    }
                    /* Start your process */
                    Console.WriteLine("Launch me");
                }
                catch (AbandonedMutexException amex)
                {
                    /* Log if abandoned */
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
            }
            return null;
        }
I think the Mutex approach is better, because you can also take back control of the application. Or if you want to go the route Skydiver suggested, try something like this. I've tested the one below, and it works fine :
C#:
        public bool IsRunning(string nameOfProcess)
        {
            Process thisProcess_FromID = Array.Find(Process.GetProcesses(), cur_ProcessID => cur_ProcessID.ProcessName == nameOfProcess && cur_ProcessID.SessionId == Array.Find(Process.GetProcesses(), cur_Process => cur_Process.ProcessName.StartsWith(nameOfProcess)).SessionId);

            if (thisProcess_FromID == null)
                Console.WriteLine("Launch me");
            return false;
        }
 
Back
Top Bottom