ProviderFailure in ManagementClassCollection

  • Thread starter Thread starter Franz
  • Start date Start date
F

Franz

When I want to get the count of the ManagementClassCollection, I get a
ProviderFailure.
I don't know why I get this error and what this error means. Can anyone help
me? Thank you.

ManagementClass manClass = new ManagementClass("Win32_CDROMDrive");
ManagementObjectCollection manObjCol = manClass.GetInstances();
if (manObjCol != null) {
try {
Console.WriteLine(manObjCol.Count);
}
catch (System.Management.ManagementException e) {
Console.WriteLine(e.Message);
}
}
 
Franz said:
When I want to get the count of the ManagementClassCollection, I get a
ProviderFailure.
I don't know why I get this error and what this error means. Can anyone
help
me? Thank you.

ManagementClass manClass = new ManagementClass("Win32_CDROMDrive");
ManagementObjectCollection manObjCol = manClass.GetInstances();
if (manObjCol != null) {
try {
Console.WriteLine(manObjCol.Count);
}
catch (System.Management.ManagementException e) {
Console.WriteLine(e.Message);
}
}
Works for me. What framework version are you running?

Willy.
 
Back
Top