A Windows Mobile device is docked when you can resolve the PPP_PEER machine name, which can be used for TCP communication between the device and the host it is docked to. This is, however, only true when the cradle is actually connected to the PC.
public static bool ActiveSyncConnected
{
get
{
try
{
IPHostEntry entry = Dns.GetHostEntry("PPP_PEER");
return true;
}
catch
{
return false;
}
}
}
Another solution (at least for industrial devices) would be to check the AC line state, i.e. whether it is currently connected to the power adapter. This is true when the device is cradled, no matter whether connected to a PC or not.
public bool CurrentlyConnectedToACLine
{
get
{
SYSTEM_POWER_STATUS_EX status = new SYSTEM_POWER_STATUS_EX();
if (GetSystemPowerStatusEx(status, true))
return status.ACLineStatus != 0;
else
return false;
}
}
[StructLayout(LayoutKind.Sequential)]
internal class SYSTEM_POWER_STATUS_EX
{
public byte ACLineStatus = 0;
public byte BatteryFlag = 0;
public byte BatteryLifePercent = 0;
public byte Reserved1 = 0;
public uint BatteryLifeTime = 0;
public uint BatteryFullLifeTime = 0;
public byte Reserved2 = 0;
public byte BackupBatteryFlag = 0;
public byte BackupBatteryLifePercent = 0;
public byte Reserved3 = 0;
public uint BackupBatteryLifeTime = 0;
public uint BackupBatteryFullLifeTime = 0;
}
[DllImport("coredll.dll")]
private static extern bool GetSystemPowerStatusEx(SYSTEM_POWER_STATUS_EX lpSystemPowerStatus, bool fUpdate);