Most spacecraft are controlled from the ground; some are controlled by astronauts inside of them. A few, like DS1, have special equipment that can navigate "on the fly." In the case of DS1, this navigation is done by a device called AutoNav.
Regardless of who or what is doing the controlling, though, there are common elements to spacecraft navigation. All navigation systems use the positions of known objects in space as well as the information coming back from the spacecraft to tell where a spacecraft is. Once the spacecraft's position is known, the flight path is plotted and thrusters are fired.
More about navigation:
How do spacecraft get to where they're going?
How does a spacecraft change course?