Phiber
Phiber

Reputation: 1103

How to send command to running program? in batch file

I have a program named myProgram.exe that's running in console on a server. On the server I can type a command in the console and it works.
On the client side, how I send command to this console using a batch file. I would like to attach to this console and pass to it a command in one line. It's possible?

Server: Windows 2003 Server Client: Windows XP or Win7

Upvotes: 0

Views: 3404

Answers (3)

MrPaulch
MrPaulch

Reputation: 1418

Detailed solution with remote.exe

On Server 'A': remote /s cmd bootSession

On Client 'B': createSession.bat:

@echo off
echo remote /s cmd session1 > commands.txt
echo @q >> commands.txt
remote /c A bootSession < commands.txt
del commands.txt
remote /c A session1

If you think about haveing more than one session you should run a counter on your client and embed client name + counter in the uid.

You could create random uid's, too.

Upvotes: 1

Phiber
Phiber

Reputation: 1103

I have modified your code createSession.bat in client B:

@echo off
echo remote /s cmd session1 > commands.txt
echo @Q >> commands.txt
runas /profile /savecred /user:User1"cmd /C %RemotePath%\remote /c computerA bootSession   < %CD%\commands.txt" 
runas /profile /savecred /user:User1"cmd /k %RemotePath%\remote /c computerA session1"  

It works fine, but the first instance of cmd (bootSession) still open even i send @Q to remote to quit. You have idea to close it and let just the second instance (session1).

Thanks another time

Upvotes: 0

ohade
ohade

Reputation: 161

you might want to use PSEXEC (SysInternals)

psexec \\%SERVER% c:\FOLDER\FILE.EXE 

Upvotes: 1

Related Questions