本文介绍了WMI中的提供程序故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用带有C#.Net 2.0,XP SP1的WMI检索CDROM驱动器详细信息.我遇到了Provider异常,找到以下代码,让我知道此异常的原因.
I am trying to retrieve the CDROM drive details using WMI with C#.Net 2.0, XP SP1. I got Provider exception, find the below code, let me know the reason for this exception.
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_CDROMDrive");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_CDROMDrive instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Drive: {0}", queryObj["Drive"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}
堆栈跟踪:
------------
Stack trace:
------------
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
at System.Management.ManagementObjectCollection.get_Count()
推荐答案
这篇关于WMI中的提供程序故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!