It can certainly be done programmatically (i.e., detection of a connected/disconnected device as you dock/undock) but that's way above my capabilities.
However, I know exactly where you are coming from because I had similar requirements for a PC I used for work: When I was on the road, it was important that the screen saver with password lock be enabled; however, once at home and docked, I wanted all that disabled. Again, not having the skills to write a Windows program to do it, I wrote two scripts (batch files) instead and placed shortcuts to them on my taskbar.
End result was that it just one simple click in order to activate a configuration...and that's pretty close to automatic.