Some over-the-counter ant sprays may work initially, but only when sprayed directly on ants. Unfortunately, they usually won't solve an ant infestation. Other sprays have a residual effect, meaning they can be effective means of getting rid of ants even if not sprayed directly on the insects.