Running a program on shutdown

how do you do it? i wiuld really like to know… because it would come in great use here at work.