If the existing receptacle or switch is connected through the holes in the back, push a jewelers screwdriver or similarly shaped tool into the slot next to each hole to release the clamp pressure and pull the wire free.
Pry the molding off the wall working at each stud. Drive a broad chisel-type joint knife between the baseboard and wall. Pull out on the handle several times to loosen the molding enough to wedge a crowbar behind it.
Reinstall the wallboard strip. Trim along the edges with a sharp drywall knife first to remove any torn paper that could created a gap behind the molding.
Carefully nail the molding just above and/or below the metal shield at each stud. Caulk the trim seams, fill the nail holes, and touch up the wall and molding paint.