如何通过 id 获取进程的命令行参数?

How to get command line args of a process by id?

我有一个 运行 进程的 ID(不是我启动的)。我怎样才能得到它的命令行参数?

您可以使用 wmi 获取此类信息

var q = string.Format("select CommandLine from Win32_Process where ProcessId='{0}'", processId);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(q);
ManagementObjectCollection result = searcher.Get();
foreach (ManagementObject obj in result)
    Console.WriteLine("[{0}]", obj["CommandLine"]);