Check if a specific exe file is running

后端 未结 8 1928
野趣味
野趣味 2020-12-01 04:44

I want to know how i can check a program in a specific location if it is running. For example there are two locations for test.exe in c:\\loc1\\test.exe and c:\\loc2\\test.e

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 05:01

    This function may help:

    using System.Diagnostics;
    
    public bool IsProcessOpen(string name)
    {
        foreach (Process clsProcess in Process.GetProcesses()) {
            if (clsProcess.ProcessName.Contains(name))
            {
                return true;
            }
        }
        return false;
    } 
    

    Source: http://www.dreamincode.net/code/snippet1541.htm

提交回复
热议问题