Matthew King
Matthew King

Reputation: 5194

Programmatic way to see if a mobile computer (laptop/tablet/etc.) is connected to a docking station

I am writing some software that needs to behave differently on a mobile device that is connected to a docking station. As a result, I need a programmatic way to check if the computer is connected to a docking station in C#/.NET.

I have tried the following:

Unfortunately, none of these seemed to work in a 'one size fits all' situation. They would work for some of my test devices, but not others.

I need to run across a variety of devices and docking stations. Are there any consistent, reliable ways to check if a device is docked in Windows?

Upvotes: 2

Views: 2214

Answers (2)

Oleg
Oleg

Reputation: 221997

You can consider to use GetCurrentHwProfile and examine the dwDockInfo filed of HW_PROFILE_INFO returned.

Upvotes: 1

PhonicUK
PhonicUK

Reputation: 13844

There is no universal way of telling this. Many docks just appear as a USB hub with a stack of devices attached and duplicating some IO ports, some do actually behave as a 'dock' which would allow what you've tried already.

What you'd likely have to do is use complete hardware profiling to check. Asking the user to undock the laptop, check all the attached devices, ask the user to dock it and then check again. You'd want to check all enumerable devices on the PCI and USB busses.

You'd also have to do a bit of magic to cope with removable devices, so you'd have to ask the user to remove them all before both checks.

Upvotes: 3

Related Questions