private static IEnumerable<string> GetCommandLines(string processName)
{
List<string> results = new List<string>();
string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", processName);
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery))
{
using (ManagementObjectCollection retObjectCollection = searcher.Get())
{
foreach (ManagementObject retObject in retObjectCollection)
{
results.Add((string)retObject["CommandLine"]);
}
}
}
return results;
}
static void Main(string[] args)
{
var result = GetCommandLines("msvsmon.exe");
Console.Read();
}
任务管理器中实际的参数如下, 该程序或得到3个item的string。