I manage to open a console application in a remote computer by using PSTools using PsExec.exe.

C:\PsExec.exe -i 2 -s -d \128.168.500.500 -u username -p password "D:\myApp.exe"

That will open a console application (not just a console) remotely.

Now I would like to execute a command in that remote console application. Is that somehow possible at all?

This is the command I want to run:

> @start.txt


Sure, start psexec the below way:

psexec \\<target> cmd

That will then just run a terminal session remotely where you can continue to execute more commands.

  • I don't want to start the command line. The command line will get started with whenever I open a .exe. Is there, in that exe, where I want to be able to write a command. Inside that console application. – Steve Sep 23 '14 at 9:56
  • I updated my question. – Steve Sep 23 '14 at 9:57
  • Okay then copy in a batch file for execution line by line or create a new batch file and call it from the psexec session. – Ben Lavender Sep 23 '14 at 10:00
  • Also that command “@start.txt” can be executed using just start.txt if it’s in your working directory or path etc of the remote machine , because you’ve specified the interactive switch it should open on the target. – Ben Lavender Sep 23 '14 at 10:12
  • Could you elaborate it? I don't understand what you said about the batch file. If you update your answer that'd be nice. – Steve Sep 23 '14 at 10:29

Could you please explain the purpose of executing >@start.txt.

Are you trying to collect the logs of "D:\myApp.exe" to >@start.txt. >@start.txt cannot run like as any .exe. So if it is going to be a log collector of "D:\myApp.exe" then try the below command line.

C:\PsExec.exe -i 2 -s -d \128.168.500.500 -u username -p password "D:\myApp.exe" >> @start.txt

Or else, please elaborate the purpose.

  • Inside that .txt file there are some commands o be interpreted by the .exe. It is in a text file so that the users can customize those commands easily before starting the application. – Steve Sep 24 '14 at 7:06

Is myapp.exe reading the command from standard input? If so, create a text file that contains @start.txt and add a redirect for stdin:

C:\PsExec.exe -i 2 -s -d \128.168.500.500 -u username -p password cmd /c "D:\myApp.exe <mycmd.txt" 

(The cmd /c syntax ensures that the < redirect applies to myapp, not to psexec.)

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.