How do you write a program close every open application

I am trying to make a program that locks a computer unless you have a password by systematically looping through and closing applications. It would also have a list of applications that the user is ok with having open, (for example a dock like rocket dock or a desktop tool like konfabulator or Rain meter). I know how to close individual processes in batch, but is their a way to only close things with a main window? If there is an easier way to achieve the same effect (such as if you can block all programs from ever opening) feel free to say that too. I am most familiar with batch, c++, java, and python, but if another language makes something easier, I am willing to try it.Thanks!

From what you are describing I guess you are talking about linux which I don't know too much about.

But to answer your question, you should see if you can either a) hook the execution pipeline to load new executables or b) if you can register to get events on something being executed then you can either send a response to deny it (if you can) or to just shut it down yourself in your program.

Personally, the idea of having this functionality is not a good thing. I really wouldn't want standard application developers to be able to do something like this, but those are two ideas.