processName.Name = @"\\dfs\ns1\Application_Data\tiny\Development\tinyLOS\tinyLOS.exe";
string wmiQuery = string.Format("select CommandLine from Win32_Process where PathName='{0}'", processName.Name);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();
我正在尝试使用WMI在C#中运行上面的代码但是在执行时我一直收到无效的查询错误。我怀疑这是逃避反斜杠的问题,但我认为我已经用@来解释了这个问题。我错过了一些简单的东西,因为它看起来应该执行好吗?
(注意:删除反斜杠时执行查询)
答案 0 :(得分:2)
您需要传递转义斜线,而ExecutablePath
不是PathName
wmiQuery = @"SELECT CommandLine FROM Win32_Process WHERE ExecutablePath =
'C:\\Program Files\\Microsoft Security Client\\msseces.exe'";
var searcher = new ManagementObjectSearcher("root\\CIMV2", wmiQuery);
foreach (ManagementObject queryObj in searcher.Get())
Console.WriteLine("CommandLine: {0}", queryObj["CommandLine"]);
对于
CommandLine: "C:\Program Files\Microsoft Security Client\msseces.exe" -hide -runkey