In real life, it works best when dealing with machines whose moving parts can become physically jammed or temporarily impeded, such as gearboxes or switches; hydraulic systems suffering particular kinds of plugs or clogs, such as fuel lines or sump pumps; motors making a buzzing or whining noise, such as often found in window air conditioners and similar appliances; or components which only function when firmly in their sockets and which have ceased to be so, such as vacuum tubes, early transistors, and some electrical connectors.
In fiction, percussive maintenance is more often found in earlier works, where most machines were built of parts large enough to see and handle individually — the likelihood of percussive maintenance being successful with a given machine tends to be inversely proportional to the degree of miniaturization that went into its design, so the technique becomes less useful over time. (For example, you could often fix an old AT&T Model 500 desk phone, and greatly impress non-technical bystanders at the same time, by slamming it down good and hard on the desk; doing the same thing with your iPhone only helps if your contract includes replacement coverage.)
For that reason, this rarely works with modern delicate electronics or futuristic solid-state circuitry/machinery (cf. Drake's camera-bash from Aliens, on Main), but the appeal of a highly emotive and easy-to-show repair technique often wins out over boring technical accuracy. In other words, Don't Try This at Home unless you really know what you're doing; repeatedly whacking your DVD player, for example, is highly unlikely to make the picture any clearer, although it may still make you feel better. (At least until you knock the tray off its rails, or just break some internal part outright. Then you have to spend the next hour dismantling the thing in order to extricate the disc, and a hundred bucks or so replacing the player, before you can go back to what you were trying to watch in the first place. Percussive Therapy might seem cheaper than the more usual kind, but...)note
Increasingly rare exception: CRT displays, whose picture quality occasionally benefited from a good whack of the palm to the side of the casing — the casing, not the glass; you won't break the glass, but you might hurt your hand, because that stuff is thick. It's also leaded, so you don't get brain cancer from the electron guns' waste X-rays.note Aren't you glad you bought a flat panel? — if you're under twenty or so, aren't you glad you've never used anything but a flat panel?