I\'m writing a C# app (specifically for laptops) and I want to be aware of the state of the lid, i.e. when is it open and when is it closed.
I\'ve already used pInvoke a
I don't think 'lid state' is guaranteed to be reflected in the power management properties. Is your interest in the lid state simply down to the monitor? If so, you could find a way to determine the properties of the integrated screen (could be an issue if they install it while connected to an external monitor) and save them. Then check the properties of the screen/s in use and act accordingly.
See System.Windows.Forms.Screen - http://msdn.microsoft.com/en-us/library/system.windows.forms.screen%28v=vs.110%29.aspx
Serial numbers can be extracted from the 'Device Parameters' keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY
. How to extract it (along with other info) is demonstrated here:
http://sourceforge.net/p/wmimonitor/code/HEAD/tree/DisplayInfoWMIProvider/WMIProvider/WMIProvider.cs
Alternatively, assuming that the callbacks still fire even if the lid close event in Windows is set to 'Do Nothing', you could perhaps consider a helper process or service to run all the time and keep track of changes. You could share the state via the registry or a file. You could also look into whether any other items of hardware (eg. touchpad) change power state on close regardless of the 'power plan' and use the GetDevicePowerState API function.