Getting a path of a running process by name

前端 未结 3 1194
花落未央
花落未央 2021-01-12 04:22

How can I get a path of a running process by name? For example, I know there is a process named \"notepad\" running, and I want to get the path of it. How to get the path wi

3条回答
  •  不要未来只要你来
    2021-01-12 04:42

    There is a method GetProcessesByName that existed in .Net 2.0:

    foreach (Process PPath in Process.GetProcessesByName("notepad"))
    {
        string fullpath = PPath.MainModule.FileName;
        Console.WriteLine(fullpath);
    }
    

提交回复
热议问题