How would you go about finding the file in which the application was started from.

In simpler terms.. You set the open with to be your application, how would you go about finding the file the application was started from using pure code. And at that even checking if it was opened using open with?

First one to give me a proper answer to this within 20 minutes gets on our board!