WMI致电获取司机
我是新用的WMI。 它是什么?
我可以在C#中使用WMI调用来获取PC上的驱动程序列表吗? 如果是的话,我打电话给哪个class级?
要列出已安装的驱动程序,您可以使用Win32_PnPSignedDriver
WMI类,如此示例所示。
using System; using System.Collections.Generic; using System.Management; using System.Text; namespace GetWMI_Info { class Program { static void Main(string[] args) { try { string ComputerName = "localhost"; ManagementScope Scope; Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null); Scope.Connect(); ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_PnPSignedDriver"); ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query); foreach (ManagementObject WmiObject in Searcher.Get()) { Console.WriteLine("{0,-35} {1,-40}","ClassGuid",WmiObject["ClassGuid"]);// String Console.WriteLine("{0,-35} {1,-40}","DeviceClass",WmiObject["DeviceClass"]);// String Console.WriteLine("{0,-35} {1,-40}","DeviceID",WmiObject["DeviceID"]);// String Console.WriteLine("{0,-35} {1,-40}","DeviceName",WmiObject["DeviceName"]);// String Console.WriteLine("{0,-35} {1,-40}","Manufacturer",WmiObject["Manufacturer"]);// String Console.WriteLine("{0,-35} {1,-40}","Name",WmiObject["Name"]);// String Console.WriteLine("{0,-35} {1,-40}","Status",WmiObject["Status"]);// String } } catch (Exception e) { Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace)); } Console.WriteLine("Press Enter to exit"); Console.Read(); } } }
此外,如果您是WMI主题的新手,您可以使用WMI Delphi Code Creator
类的工具来探索WMI内容并生成访问WMI的代码。