簡體   English   中英

WMI錯誤,使用C#中的簡單查詢

[英]WMI error with a simple query in C#

我試圖在Windows 2000上使用以下代碼:

foreach (Process p in Process.GetProcesses())
{
    if (p.MainModule.FileName.EndsWith("calc.exe"))
    {
        using (ManagementObjectSearcher mos = 
                   new ManagementObjectSearcher(
                     "SELECT CommandLine,ExecutablePath 
                       FROM Win32_Process WHERE ProcessId=" + p.Id.ToString()))
        {
            using (ManagementObjectCollection moc = mos.Get())
            {
                foreach (ManagementObject mo in moc)
                {
                    MessageBox.Show((string)mo["CommandLine"]);
                    return;
                }
            }
        }
    }
}

這在Windows XP和更高版本上可以使用,但是在Windows 2000上失敗,並顯示“無效查詢”錯誤。 根據MSDN ,Windows 2000和更高版本支持Win32_Process對象,因此我不確定自己在做什么錯。 任何幫助將非常感激。

不好意思 我剛剛意識到“ CommandLine”字段僅在Windows XP和更高版本中使用。 問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM