Windows Program: How to snoop on command line arguments? - windows

I am trying to reverse engineer the build system of a commercial Windows based IDE, so I can use make to build my project.
A program is launched to perform a task, and I need to know what command line arguments are passed to this program when it is run. However the windows process viewer does not show the command line arguments.
Is there any way to see what command line arguments are being passed when the program is launched?
(Actually it just occurred to me that I should substitute a stub program to read the command line args. Still, I'd like to know if there's an easy way).

Sysinternals Process Explorer lets you do that.

Related

Is it possible to obtain the _raw_/_unprocessed_ command line?

The windows API provides GetCommandLine() which returns the cooked command line used to start a process.
For instance, if a console application is started with the command:
MyProg.exe > OutputHere
The command line seen by MyProg.exe will not include the portion
> OutputHere
I'd like to somehow get the command line exactly as it was. Is this possible ? and if yes, how ?
Suggestions in C and/or plain (no objects) Delphi greatly appreciated. Creative solutions welcome (hopefully, not requiring ring 0 code.)
Thank you very much for your help.
NOTE: I can tell if the input/output, etc has been redirected but, that is not what I'm looking for. I need the original/uncooked command line.
The redirection or piping of stdin, stdout and stderr is handled the command interpreter, typically cmd.exe. The interpreter parses the command and creates the necessary files and pipes, and then creates the one or more processes needed to implement your command.
The processes that are created have no knowledge of the original command, they only get that part of the command that is not related to piping and redirection.
So what you are trying to do is not possible, at least within your process. The only thing that knows the original command is the command interpreter.
Whether or not you can retrieve the full command line including the pipe commands depends on whether your start the program in a command window or for example using the "Run" command from the Start menu. If you use the "Run" command from the Start menu GetCommandLine actually retrieves the full command line including the redirection commands, but redirection does not work as it seems to be a feature of CMD.EXE.
As others have pointed out, what are you trying to achieve here / why do you need to capture the redirection commands?

How to give interactive inputs in a single line for .exe windows

I am trying to automate one process which involves giving interactive input to a .exe utility. It expects the user-input for each step. I wanted to give all those values at single time while giving that command only. For eg: ./test.exe 8\n1\n0 etc. I have tried multiple ways to give input to the 'test.exe' utility like 8\n1\n0 | ./test.exe and 8,1,2 | ./test.exe. None of these worked. Any help how to pass these options 8,1,2 to the interactive utility test.exe in single line so that it will be helpful for my automation
There is no set way to automate a 3rd party program with Powershell. Not all utilities even offer the ability to do so.
I'd look in the utility documentation for any switches.
Try the following to see if you can get any built in help: test.exe -h, test.exe /h, test.exe /?, test.exe -?
use the sysinternals strings utility to try and find anything that look like command line switches inside the exe that you can take advantage of.
https://technet.microsoft.com/en-us/sysinternals/strings.aspx?f=255&MSPPError=-2147217396
The answer depends entirely on how your executable works.
If the executable reads from standard input, you can redirect input to it as follows (PowerShell):
PS C:\> 8,1,2 | .\test.exe
This won't work if the executable doesn't read from standard input or if it clears the console input buffer.
The executable may also let you provide command-line arguments that specify the needed input, but this depends on the executable.

Autohotkey script running program with command line arguments

I am using autohotkey to automate some manual process.
I have to run a java command line program(.java) that accepts couple of command line arguments.
I want to run this java program from autohotkey after executing some pre-defined tasks in the automation.
How would I do this?
I think that this is what you are looking for. In this example, I over-ride the company default search engine inside IE.
#i::Run "C:\Program Files\Internet Explorer\iexplore.exe" http://www.google.com
Basically, put the run pointer between double quotes and the arguments after that. Let me know how you resolve it.

VB6 Debugger - Command line arguements

In the VB6 IDE there is a window were you can specify command line arguements (for debugging). If you create a .exe with arguements specified, will they be published with the application? I don't believe they will.
No, they will not. This is just for testing your application if it uses command line arguments. It allows you to specify your command line arguments and step through exactly like if the program was called with those command line arguments.
For example, you normally pass parameters by simply calling your EXE and providing the parameters at the same time. So, if you normally call your program like such
C:\test.exe /test /inet /copy
You would simply set the command-line arguments to
/test /inet /copy
in the VB6 IDE

Install MathLink program with arbitrary PATH environment

Is it possible to use Install[] to start a MathLink program with a custom PATH environment variable?
I am trying to use mEngine to connect Mathematica to MATLAB on Windows. It only works if mEngine.exe is launched when the PATH environment variable includes the path to the MATLAB libraries. Is it possible to modify the PATH for launching this program only, without needing to modify the system path? Or is there another way to launch mEngine.exe?
#acl's solution to wrap mEngine.exe in a batch file, and temporarily modify the PATH from there, works correctly:
I used this as the contents of mEngine.bat:
set PATH=c:\path\to\matlab\bin\win32;%PATH%
start mEngine.exe %*
*% ensures that all command line arguments are passed on to mEngine.exe
start is necessary to prevent the command window from staying open until mEngine.exe terminates
It can be started using Install["mEngine.bat"].
Since all the information that is needed for the kernel to communicate with mEngine.exe is passed by Install[] as command line arguments, all we need to do is launch mEngine.exe with these arguments. It is not necessary for Install[] to know the location of mEngine.exe, the important thing is that the process gets launched with the correct command line arguments, which is ensured by %*.

Resources