c# 获取指定进程的命令行
using System; using System.Management; class Example { static void Main(string[] args) { string processName = "javaw"; // 进程名称,可根据实际情况进行修改 ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE Name='" + processName + ".exe'"); foreach (ManagementObject process in searcher.Get()) { string commandLine = process["CommandLine"].ToString(); Console.WriteLine("Process {0} started with command line: {1}", processName, commandLine); } } }
注意:要以管理员身份运行上述代码,否则部分进程获取到的结果为空
桂棹兮兰桨,击空明兮溯流光。