We put our DS in time out, and it doesn't necessarily stop him doing it again, but it's good for taking him out of the situation and breaking the pattern.
Keeping him in the spot started off as hard work... 1 day I spent 18 minutes putting him back in the spot for a 2 minute time out! But he got the point eventually. It takes a whole lot of persistence.

When we're out, if he is running off or touching things he shouldn't, I tell him not to do it once, if he does it again, i warn him - do it again we will go home. The key here is to follow through. Last week, he touched again, so that was it, we left to go home (kicking and screaming).
Today when we went out, I said remember what happened last time at the shops? I had a chat to him about the rules and kept reminding him at the shops and he was heaps better.

Some days, no amount of time out or talking helps... If he's just in a cheeky mood, I just try to breathe though it! He is just testing the boundaries, and this is probably the most important time to follow through with discipline and set the limits - over and over again!