Search code examples
windowsexecutionapplication-design

Intercepting command switches


Is it possible in Windows to intercept the command switches passed from one applicaiton to another?

To clarify, imagine we have two binaries: a wrapper and a main executable. The executable only launches correctly if the wrapper passes the appropriate command along with the execution (e.g. program.exe /start 12345).


Solution

  • If you're talking about intercepting an existing application, sure, you can just replace the executable with your wrapper. So, for example, if you wanted to intercept AcroRd32.exe, just rename it to MyAcroRd32.exe and write your own AcroRd32.exe which:

    • does something with the parameters (store them, change them, print them, ...); then
    • call MyAcroRd32.exe as a second stage (assuming you want to, based on the parameters).

    If you're talking about not allowing the executable except by the wrapper, I've also used the method you propose (under UNIX but the theory is the same) - I had the wrapper pass a super-sekrit password ("deoxyribonucleic") on the command line (or in the environment) so that the executable would do nothing without that.

    It's not bullet-proof but things rarely are. It will usually block all but the most determined people.