WMI调用来获取驱动程序 [英] WMI call to get drivers
本文介绍了WMI调用来获取驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新使用WMI。这是什么?
I am new using WMI. What is it?
我可以使用WMI调用在C#中,例如让我的电脑上的驱动程序列表? ?如果是这样,我该调用哪个类
Can I use WMI call in C# for example to get list of drivers on my PC? If so, which class do I call?
推荐答案
要列出已安装的驱动程序可以使用的 Win32_PnPSignedDriver
WMI 。类是显示在此示例
To list the installed drivers you can use the Win32_PnPSignedDriver
WMI class as is show on this sample.
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代码造物主$的工具C $ C>
探索WMI内容,并生成代码来访问WMI。
Also if you are new in the WMI topic you can use a tool like the WMI Delphi Code Creator
to explore the WMI contents and generate code to access the WMI.
这篇关于WMI调用来获取驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文