I have an executable: foo.exe

Another process executes foo.exe with certain command line arguments. I cannot modify the process that executes foo.exe, nor change the filename it executes.

I want to add an additional command line argument (-bar) to that call.

The final result will be: foo.exe -bar <args_passed_by_process>

Do you know of any way to do that?

3 Answers 3


I know this is an old post, but I had this exact problem today.

Basically a JxBrowser instance launced by a third party application was returning a http error 401 when it was supposed to open a login window. This happened on all our domain PC's and the provider was not very helpful in finding a solution. Seeing as I was basically on my own, I needed to pass a --remote-debugging-port parameter to the chromium executable so I could actually get this resolved

Anyway here is the solution I came up with. It's very hacky, but it works

I first tried creating a .bat file that just runs the input along with the added parameter like below

> @echo off
> %* -bar

I then created a debugger key calling this bat file in the "Image File Execution Options" like below

> reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\foo.exe" /v Debugger /t REG_SZ /d "C:\Path\To\This\batch\file.bat" /f

What this does is everytime Foo.exe is launched it actually runs the command '"C:\Path\To\This\batch\file.bat" Foo.exe', which in turn runs the command 'Foo.exe -bar'. This means that calling 'Foo.exe -foobar' would result in 'Foo.exe -foobar -bar' being called instead

The problem I then ran into is that because the batch script calls Foo.exe, it actually calls itself in an endless loop, everytime adding -bar to the command so you actually end up running "C:\Path\To\This\batch\file.bat" Foo.exe -foobar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar -bar etc."

What I ended up doing was modifying the script to delete the debugger registry key before launching foo.exe and then re-adding it, like so:

> @echo off
> reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\foo.exe" /v Debugger /f
> %* -bar
> reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\foo.exe" /v Debugger /t REG_SZ /d "C:\Path\To\This\batch\file.bat" /f

This results in the following:

  1. Application attempts to launch 'Foo.exe -foobar'
  2. Instead of launching Foo.exe, '"C:\Path\To\This\batch\file.bat" Foo.exe -foobar' is called instead
  3. The batch script deletes the debugger registry key
  4. When Foo.exe is called on the next line it actually launches foo.exe with the added -bar parameter instead of the .bat file
  5. The registry key is re-added so that the next time Foo.exe is launched, it will once more run it through the batch script and add the -bar parameter

(you might have to edit the permissions of the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\foo.exe" key, so that the application calling foo.exe actually has permission to edit it)

I'm certain there's a better solution to this, but I for the life of me could not find one.

  • Instead of deleting the reg key, I copied the exe and called the copy e.g. foo2.exe Apr 7 at 6:38

Try: rename foo.exe to something else (e.g. foo1.exe), then write a simple command line program in a language that compiles to an .exe (FreeBasic, C#, C, whatever suits you). The language must have a 'shell' command or facility, i.e. use the OS to execute an external app (the new foo1.exe) The program you write, when compiled, will be the new foo.exe. It will be quite a simple app - it just accepts all the arguments that the other process sends to foo.exe, prepends your -bar argument to the list, then calls foo1.exe with the amended argument list.

If your calling process would wait for foo.exe to terminate and return an exit code, you may need to replicate that behaviour.

  • This works as long as the first process in the execution chain (the one that can't be modified) does not wait for the subprocess to exit and process it's exit code and/or the command output.
    – Robert
    Oct 11, 2019 at 17:58
  • Then write that into the code. Oct 11, 2019 at 17:59
  • @MichaelHarvey this is exactly what I did and designed it to wait for the sub-process and return the sub-process exit code or any error code it experienced trying to run the sub-process. Oct 11, 2019 at 18:32
  • And what was the result? Oct 11, 2019 at 19:41

set up image file execution options in registry to include them whenever application is ran or launched from any other application or association event that launches it

you could also append the argument in a giant pipe chain, make a shortcut .lnk that includes argumrnets of main exe, foo1 --> "C:\users\test\Foo2.exe --bar"

you could use hwnd tunneling

you could hook the process or api possably

pipe / sdout output to file >> use findstr than reinject dynamic results back into command back to foo2.exe

some random ideas

use cmd SET command to introduce enviromental universal variable that includes it by default within its path, this way you wont ever actually need the path location of the file and it can be ran from anywhere and recognized as a default windows service/program and as such you can also manipulate any additional cli args into its 'path'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.