Click here to Skip to main content
15,881,832 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hello everyone!

Here is the thing, I'm making a windows service in C# that monitors if the laptop is connected to the docking station, but I´m having some problems with this part. I had already look in the if there is a registry entry, I just found DockingState, but the value never change, is there other way? Maybe with the ManagementObjectSearcher?

Thx!

M
Posted
Comments
Bernhard Hiller 6-Mar-13 2:58am    
Good question - and seems complicated to answer correctly. The registry key suggested below shows that my laptop is not docked, though it is...
According to http://www.fryan0911.com/2009/06/c-eject-or-undock-laptop-pc.html, it is possible to "un-dock" the laptop though it remains physically attached to the docking station, and that registry key is set to 1. Does not hold true for my current situation, as network, power, keyboard, mouse are plugged into the docking station and still can be used, i.e. the laptop uses the docking station.
(I did not downvote that answer with the registry key, and I believe that the other solutions actually also use that key in some way.)

Hmm, interesting. AFAIK, docking / undocking is the function of a driver not the OS. May be there is a way to get the state, check if this helps

CM_Is_Dock_Station_Present[^]

CM_Is_Dock_Station_Present_Ex [^]
 
Share this answer
 
Comments
#realJSOP 12-May-11 11:09am    
But a driver may affect what WMI reports/sees.
Yusuf 12-May-11 11:37am    
Absolutely. What I was trying to point the OP was that not to expect too much from the native OS
Look behind the laptop. If it's plugged into the docking station, it'll be pretty obvious.

Seriously though, you might be able to do it with WMI. No guarantees, and google is your friend.

EDIT ===============

Oh come on! Since when can't we add a little humor to our answers? I followed up by providing a lead for the guy.
 
Share this answer
 
v2
Comments
wizardzz 12-May-11 10:50am    
You didn't drive to his house and check if the laptop was docked for him...
#realJSOP 12-May-11 11:09am    
But I told him how to check on his own. I guess I could have provided a link to a multimedia help file of some sort, but youtube is just as easily accessible as google.
wizardzz 12-May-11 11:11am    
Well, you might need to teach him how to use his eyes, hands, brain, etc.
HimanshuJoshi 12-May-11 10:52am    
5 to compensate for humor deficent people.
S Houghtelin 12-May-11 12:23pm    
5, Because it is funny.
DockingState is an enumerated value, if the value is 0 it will never change. If the value is 3 you prbably need the driver from the manufacturer of the laptop.


As Yusef has already stated, it is a function of the driver, not the OS.

C#
typedef enum  {
  DockStateUnsupported   = 0,
  DockStateUnDocked      = 1,
  DockStateDocked        = 2,
  DockStateUnknown       = 3
} DOCKING_STATE;

 
Share this answer
 
In WMI you can get the value from Win32_SystemEnclosure -> ChassisTypes but is doesn't change if you dock and undock for me.

In RegDB: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\IDConfigDB\CurrentDockInfo\DockingState .
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900