Start by using a sharp utility knife to cut through the layer of paint where the molding meets the wall.
Next, Tap a thin pry bar between the molding and the wall.
Once the molding has been loosened from the wall, remove the pry bar and drive in wood shims to widen the gap.
Work your way along the molding using the pry bar and shims to loosen the molding.
After the molding is loose, use a larger flat pry bar for more leverage and finish removing the molding from the wall.
Remove the nails from the molding by pulling them out from the back of the wood with a pair of pliers. This causes less damage to the molding than hammering them out through the front.