First, write down the schedule of all the things you'll be doing during the all-nighter, including when it ends. This is so that you don't forget to do anything while your brain is half-fried, and also so you know with certainty when you can crash and sleep.
Then, make sure you have food and drink or access to it. People need energy to stay awake, and the sugar in pop isn't going to be enough usually. If you are hungry, eat. And try to make it something vaugely nutritious. A stomach full of junk food won't do you any good unless you're used to that sort of thing. If you know of certain legal substances that keep you more awake, keep them on hand.
At some point, most people get that icky tired feeling that, for me, is centered in my chest for whatever reason. This will happen a couple of hours after your normal bedtime, as your body is wondering what the hell is up and trying to get you to let it sleep. At this point, I reccomend a short nap. It should be just the right length to get you a touch of REM sleep, but probably no longer than an hour. If you are really tired and think you might fall asleep quickly, shorten the nap, so that you aren't in too deep when your alarm goes off (yes, set an alarm. Duh). One nap may be all that is required for a 40-hour all-nighter, but this may vary from person to person.
Go through your normal morning routine at the appropriate time, especially if this involves a shower. This will signal your brain that if it wasn't awake already, it should be real soon. If you usually take showers at night, don't take one unless you smell, because it might put you to sleep.
If your mind starts to wander, take a break. Node. Go outside and get some fresh air, look at the stars or at the sunrise, talk to a friend, whatever.
If you usually study with music, play it.
Before you crash at the end, brush your teeth. You'll thank yourself when you wake up.