2010-12-14 42 views

回答

2

嘗試這個代碼並檢查this。 也下載WMI Code Creator(在谷歌上查詢,因爲我無法連接它,因爲我的聲譽< 10)可以輕鬆測試您的WMI查詢。

using System; 
using System.Management; 
namespace WMISample 
{ 
    public class MyWMIQuery 
    { 
     public static void Main() 
     { 
      try 
      { 
      ConnectionOptions oConn = new ConnectionOptions(); 
      oConn.Impersonation = ImpersonationLevel.Impersonate; 
      oConn.EnablePrivileges = true; 
       string[] arrComputers = "clientName"}; 
       foreach (string strComputer in arrComputers) 
       { 
        Console.WriteLine("=========================================="); 
        Console.WriteLine("Computer: " + strComputer); 
        Console.WriteLine("=========================================="); 


         ManagementObjectSearcher searcher = new ManagementObjectSearcher 
         ( 
          new ManagementScope("\\\\" + strComputer + "\\root\\CIMV2", oConn), 
          new ObjectQuery(@"SELECT * FROM CIM_DataFile WHERE Name = 'WhatyouWant.ToSearch'") 
         ); 


        foreach (ManagementObject queryObj in searcher.Get()) 
        { 
         Console.WriteLine("-----------------------------------"); 
         Console.WriteLine("CIM_DataFile instance"); 
         Console.WriteLine("-----------------------------------"); 
         Console.WriteLine("Path: {0}", queryObj["Path"]); 
        } 
       } 
      } 
      catch(ManagementException err) 
      { 
       MessageBox.Show("An error occurred while querying for WMI data: " + err.Message); 
      } 
     } 
    } 
} 
+0

謝謝..它工作...! – rakzz 2011-01-04 05:57:09

相關問題