开发者

Why can't I get Win32_UninterruptiblePowerSupply to work?

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 Visua开发者_如何学运维l 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!


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜