The need to start programs remotely can be very useful. Specifically I needed to be able to start a handful of applications remotely simply to cover the possibility of failure.
Two components were necessary to make the remoting work. First, a simple application is needed to simply accept arguments and program names and submit them for remote execution. Secondly, an NT service was needed on any machine wishing to allow the remote execution to take place.
To install the service, simply execute the following command after downloading the .exe:
After executing this command, go into the services manager (from the administrative tools in control panel) and be sure the service is set up to be able to interact with the desktop:
Simply download the application and place it in the path on any machine wishing to submit programs for remote execution.
Starting a program remotely
To execute a program remotely, simply invoke rexec.exe and pass it the following parameters:
- ip address of machine to process program.
- name of program/script/batch file.
- arguments to be passed to the program/script/batch defined in argument 2 when being started remotely.
Example: To start notepad on machine at IP 188.8.131.52 and have it initially load a file \\fileserver1\test file.txt rexec would be given the following arguments:
rexec 184.108.40.206 notepad.exe "\\fileserver1\test file.txt"
Note that for this to work properly, the remote execution service must be installed and started on the machine @ 220.127.116.11.
In the spirit of code re-use, the NTService class was taken from an article by TODD C. WILSON on CodeGuru.com. The class was originally created by Joerg Koenig.
The service simply listens for connections on a pre defined port. When connections are received from the rexec application instances they are threaded off into connection processing threads. The connection threads simply grab the program and it's arguments off the socket, start the program, and terminate. The remote execution application connects to the service at the specified IP. Next the app sends the program name and arguments to the remote service.
That's it. Nothing complicated. But quite useful. Please let me know if you have comments or ideas for improvement.