I have recently had a D40 in that was stuck in 4wd , i looked on this forum and followed some points form other users , like checking A.B.S sensors , fitting upgrade solinoids to transfer box but had no luck . After exhausting all other options i decided to remove the motorised plastic housing on the back of the transfer box 2 x 12mm bolts and an 8 pin multi plug with 7 wires . With the box removed , all wheels off the ground get someone to start the vehicle and let it idle in 1st gear ,using a large flatblade screwdriver insert into the hole where the box was and move slot slowly in both directions , then get the person inside to move the switch through 2wd 4wdh and 4wdl . Return to neutral and switch off engine . By doing this it allows the motor to reset and the gearbox to reset. ( mine had been stuck in mud and had wound the gearbox up ) refit motor and recheck . Hopes this helps