0
我試圖反轉以下查詢:我的WMI查詢有什麼問題?
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = 4856")) {
foreach (ManagementObject mo in searcher.Get()) {
Debug.WriteLine(mo["CommandLine"]);
}
}
它返回預期的結果:
C:\ WINDOWS \ EXPLORER.EXE
分爲:
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT ProcessId FROM Win32_Process WHERE CommandLine = 'C:\\Windows\\Explorer.EXE'")) {
foreach (ManagementObject mo in searcher.Get()) {
Debug.WriteLine(mo["ProcessId"]);
}
}
它引發了一個Invalid query
異常,而不是進程ID。