gpt4 book ai didi

c# - WMI 调用以获取驱动程序

转载 作者:行者123 更新时间:2023-11-30 14:34:55 25 4
gpt4 key购买 nike

我是 WMI 新手。这是什么?

例如,我可以在 C# 中使用 WMI 调用来获取我的 PC 上的驱动程序列表吗?如果是这样,我应该调用哪个类?

最佳答案

要列出已安装的驱动程序,您可以使用 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 的代码。

关于c# - WMI 调用以获取驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13132674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com