Reputation: 1420
I have some simple code:
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("select * from Win32_UninterruptiblePowerSupply");
ManagementObjectCollection items = searcher.Get();
foreach (ManagementObject item in items)
{
// Some code here...
}
The "items" object is semi-null. It's actually an object, but a call to .Count or anything else throws an exception.
I do have a standard USB-compliant UPS hooked up, this is Windows 7, and I'm using Visual Studio 2010 on a 64-bit machine. I did add a manifest and requireAdministrator too.
Other WMI classes work, but this one doesn't. I'm out of ideas - help!
Upvotes: 2
Views: 574
Reputation: 11
try a CIM_UninterruptiblePowerSupply:
' UPS Availability (WMI)
Private Function UPSavailability() As String
Dim s As String = ""
UPSavailability = s
Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM CIM_UninterruptiblePowerSupply")
For Each queryObj As ManagementObject In searcher.Get()
s = queryObj("Availability")
Next
Return s
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
Upvotes: 1
Reputation: 16828
Well from the MSDN documentation for Win32_UninterruptiblePowerSupply it states that:
Beginning with Windows Vista, this class is obsolete and not available because the UPS service is no longer available. This service worked with serially attached UPS devices, not USB devices.
Upvotes: 3