I spray WD-40 on metal parts in a high moisture area to prevent rust. But in one particular case, I don't want the oil getting on other things in a tight area, so I'm reluctant to use the spray. Is there like a non-spray equivalent of WD-40 that I could smear on by hand or coat with a paint brush to the thing I want to protect from rust? It should ideally protect against rust for several years without requiring any more applications.
You can buy WD-40 in gallon cans that are not aerosol spray. These are meant to refill manual pump spray bottles, but you can use it in the way you proposed of course.
But if you want it to stick around for longer, it might be better to use something like actual grease or even paint. WD-40 is pretty thing, and does evaporate.
Cosmoline. Or grease, but cosmoline is (now) formulated specifically for rust prevention.
Petroleum jelly or Vapo-rub are moderately effective and perhaps easier to clean off, not to mention being available at any drug store or grocery store.