Transition-metal-molecular sandwich nanowires as magnetic on/off switch