0

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

Steve
  • 203
  • 6
  • 13

3 Answers3

1

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.

Ben Lavender
  • 274
  • 1
  • 5
  • 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 09:56
  • I updated my question. – Steve Sep 23 '14 at 09: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
  • You want to run the first command then be able to execute the start.exe file? Am I correct? – Ben Lavender Sep 23 '14 at 10:37
  • I have the console application running. Now I want to execute the following command `@start.txt` which points to a text file, not an exe. – Steve Sep 23 '14 at 11:18
0

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.

vembutech
  • 390
  • 1
  • 8
  • 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 07:06
0

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.)

Jay Davidson
  • 1
  • 1
  • 2