Modification
You must modify a Webcam before you can use it for astrophotography. Remove the Webcam's lens and replace it with a 1.25-inch telescope adapter. This modification lets you insert the Webcam into a telescope's focuser and use the telescope as a lens for the CCD chip. Keep in mind, disassembling the Webcam voids the manufacturer's warranty.
Software
For best results, use the Webcam with video recording software to capture hundreds of frames of the astronomical target. Use a freeware frame-stacking program such as Registax, K3CCDTools or PixInsight to layer the individual frames to simulate long exposure photography. Stacking the individual images reveals details otherwise unseen in a single frame.
Considerations
Webcams feature either a CCD or complementary metal-oxide semiconductor (CMOS) chip for capturing video and still images. Only Webcams equipped with a CCD chip are capable of astrophotography. CMOS-based webcams are not sensitive enough to capture the details of distant celestial objects.