What the title says, really.

I've looked at examples from pscode and here but haven't quite managed to do it.

I would like to write a function or routine that would be called when a button is pressed.

Ex. Button1 pressed -> check for program X. If program X is open, close it. If not, tell the user program is not open.

Thanks in advance.