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

时间:2015-03-06 18:38:10

标签: c# .net windows process

我有一个正在运行的进程的ID(由我不启动)。我怎样才能获得命令行参数?

1 个答案:

答案 0 :(得分:0)

你可以用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"]);