A question came up on our forums and so I investigated writing a wrapper for the GetSystemPowerState API function. This allows you to retrieve the power state name, and also a bitmask of flags - Is the backlight on, is the device password protected etc. This is the result in VB.NET. We will add it to the wish list for the next version of the library.
<DllImport("coredll.dll")> _Public Shared Function GetSystemPowerState(ByVal pBuffer As System.Text.StringBuilder, ByVal Length As Integer, ByRef pFlags As PowerState) As IntegerEnd Function<Flags()> _Public Enum PowerState[On] = &H10000 '// on stateOff = &H20000 ' // no power, full offCritical = &H40000 '// critical offBoot = &H80000 ' // boot stateIdle = &H100000 ' // idle stateSuspend = &H200000 ' // suspend stateUnattended = &H400000 ' // Unattended state.Reset = &H800000 ' // reset stateUserIdle = &H1000000 ' // user idle stateBackLightOn = &H2000000 ' // device screen backlight onPassword = &H10000000 ' // This state is password protected.End EnumPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim sb As New System.Text.StringBuilder(260)Dim flags As PowerState = 0Dim ret As Integer = GetSystemPowerState(sb, sb.Capacity, flags)TextBox1.Text = sb.ToString()TextBox2.Text = flags.ToString()End Sub
The last method is just a very simple example of calling the function and displaying the result.
Powered by: newtelligence dasBlog 2.1.8102.813
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2008, Peter Foot
Contact Me