If any person sues in any court of this state, in any action, wherein the plaintiff may have costs in case judgment is entered in favor of the plaintiff and the action is voluntarily dismissed by the plaintiff or is dismissed for want of prosecution or judgment is entered against the plaintiff, then judgment shall be entered in favor of defendant to recover defendant's costs against the plaintiff (except against executors or administrators prosecuting in the right of their testator or intestate), to be taxed, and the costs shall be recovered of the plaintiff, by like process as the plaintiff may have had against the defendant, in case judgment had been entered for such plaintiff.
735 ILCS 5/5-109