2

I have a laptop that runs Windows 7, but may eventually move to Windows 10. I would like to have my own utility that detects when the laptop is docked or undocked, then change the power profile settings. I already have it set to do what I want when it's powered by the battery versus AC in the standard power Windows profiles, but I want a different power plan when the laptop is on the docking station than when it's just plugged into the AC adapter and not on the docking station.

So far, I have a working program that starts up with only a little icon in the system tray, and it will make the changes I want when it's docked versus undocked, BUT the way I'm determining the laptop is docked is by looking for the specific hardcoded monitor name I have connected to my docking station (e.g. "Samsung U32D970Q") via EnumDisplayDevices calls whenever WM_DEVICECHANGE happens.

The main problem is if I ever change the monitor, then the program will stop working. I could pass a parameter to the program on startup with the name of the monitor to look for, but I'm trying to find out if there is a better way. Am I being silly doing it this way?

Is there some Windows 7+ feature where the OS can tell that a laptop is on a docking station or not?

EJ42
  • 61
  • 5
  • If your dock provides power, [consider monitoring the AC Line Status.](http://stackoverflow.com/questions/7355331/check-if-computer-is-plugged-into-ac-power-in-batch-file) – user4581301 Oct 04 '16 at 22:09
  • @user4581301: Thanks, but I also provide AC power when I'm at home from the power brick. The problem is that there is one DC case covered by Windows, but I have two separate AC cases that I'm trying to handle differently. One AC from dock and one AC from power brick when not on dock. It may seem silly, but I want the big monitor screen to stay on at work to show the time on my screensaver while I'm up at my workbench. When I'm at home, I want the laptop's screen to go to sleep so I don't see it out of the corner of my eye when playing a game or something on my main PC. – EJ42 Oct 05 '16 at 20:09
  • An old question but if someone arrives here, at https://github.com/manutalcual/winredock you have sources to do exactly that. I did that software BTW. – Manuel Nov 22 '18 at 15:32

1 Answers1

0

I faced similar problem trying to determine if my laptop is docked. My ultimate goal is to connect laptop power supply from docking station to a smart plug and use Google Home Assistant to turn laptop on/off using voice commands. For turning on laptop when AC power is back, you need to enable "Wake On AC" in BIOS. The problem is when AC is cut, laptop will still be running on battery. I needed a way for a background task to shutdown Windows properly when these conditions are met:

1) Power supply to laptop has changed from AC to DC

2) The laptop is docked to docking station

The above conditions ensure that laptop will not shutdown when I just undock. I found out that extra devices are present in Device Manager when laptop is docked. My solution is to enumerate all devices when dock/undocked and save results to two text files and compare them using windiff to see the differences. Just use one or two of the "extra device" differences to determine if laptop is docked.

For my DELL laptop+docking station setup, "HID-Complaint*" devices are always present when docked and missing when undocked. I have tried using CM_Is_Dock_Station_Present and GetCurrentHwProfile but both never report dock status correctly.