Am trying to check is a specific application is running in the windows task manager, but the code isnt working

using UnityEngine;
using System.Diagnostics;

public class ApplicationChecker : MonoBehaviour
{
    public string applicationName = "Task Manager"; 

    void Update()
    {
       AppCheckCondition();
    }

    public void  AppCheckCondition ()
    {
          if (IsApplicationRunning(applicationName))
        {
            print("Application is running");
        }
        else
        {
            print("Application is not running");
        }
    }

    bool IsApplicationRunning(string appName)
    {
        Process[] processes = Process.GetProcessesByName(appName);
        return processes.Length > 0;
    }
}

Check your results, see if you’re getting any processes at all or any exceptions in the runtime logs.

In today’s computing environments there may even be additional permissions necessary to do stuff like this.

Also, if this is in IL2CPP, System.Diagnostics.Process has not been implemented in IL2CPP.

Beyond that…

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Thank you a lot for the insight.