Click here to Skip to main content
15,867,704 members
Articles / Desktop Programming / MFC
Article

Executing programs remotely in Windows NT/2000/XP

Rate me:
Please Sign up or sign in to vote.
4.27/5 (34 votes)
16 Jan 20032 min read 337.2K   10.1K   74   81
Starting programs on different machines is easy using these utilities.

Introduction

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.

Overview

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.

Service Installation

To install the service, simply execute the following command after downloading the .exe:

Image 1

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:

Image 2

Application Installation

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:

  1. ip address of machine to process program.
  2. name of program/script/batch file.
  3. 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 123.21.61.12 and have it initially load a file \\fileserver1\test file.txt rexec would be given the following arguments:

rexec 123.21.61.12 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 @ 123.21.61.12.

The code

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.

Summary

That's it. Nothing complicated. But quite useful. Please let me know if you have comments or ideas for improvement.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Chief Technology Officer
United States United States
Working to keep a technology company up to date. Wondering when Microsoft will hire a fresh, innovative guy to run the company.

Comments and Discussions

 
Questionsocket connection failed Pin
oneit solution6-May-12 21:31
oneit solution6-May-12 21:31 
QuestionPSExec could be the solution to all of you that have problems. Pin
ExoticmE31-Oct-11 8:51
ExoticmE31-Oct-11 8:51 
Questionrexec is giving connection refused Pin
maestromani20-Sep-11 5:29
maestromani20-Sep-11 5:29 
AnswerRe: rexec is giving connection refused Pin
AZeitler13-Dec-11 10:20
AZeitler13-Dec-11 10:20 
GeneralI have the program working locally on one windows xp pro machine but can't install service in windows 7 Pin
Stephane Poirier23-Aug-11 11:55
professionalStephane Poirier23-Aug-11 11:55 
GeneralSuggestions for people who have problems Pin
jdixon227826-Mar-10 6:21
jdixon227826-Mar-10 6:21 
Question'Local System' can't access network share folder Pin
Sekhar Kumar5-May-08 6:37
Sekhar Kumar5-May-08 6:37 
Generalruntime to terminate Pin
kalle10-Dec-07 5:46
kalle10-Dec-07 5:46 
GeneralSocket Connection Failed Pin
yug_chary12-Oct-07 1:12
yug_chary12-Oct-07 1:12 
GeneralRe: Socket Connection Failed Pin
Eli Hazan27-Mar-08 11:07
Eli Hazan27-Mar-08 11:07 
GeneralRe: Socket Connection Failed Pin
vipul052719-Nov-09 18:11
vipul052719-Nov-09 18:11 
GeneralRe: Socket Connection Failed Pin
nax2283-May-10 23:53
nax2283-May-10 23:53 
GeneralRe: Socket Connection Failed Pin
xytsrm22-Jan-11 4:04
xytsrm22-Jan-11 4:04 
GeneralImprovment issues Pin
Elad raz14-Mar-07 1:50
Elad raz14-Mar-07 1:50 
Generaloutput Pin
sdev4003-Jan-07 13:39
sdev4003-Jan-07 13:39 
GeneralRemote execution does not work Pin
autoguy10011-May-06 3:42
autoguy10011-May-06 3:42 
QuestionWhy is it asking for username and password? Pin
learningvisual5-Apr-06 12:49
learningvisual5-Apr-06 12:49 
AnswerRe: Why is it asking for username and password? Pin
jkleiss25-Sep-06 10:11
jkleiss25-Sep-06 10:11 
AnswerRe: Why is it asking for username and password? Pin
Blades6-Mar-08 6:21
Blades6-Mar-08 6:21 
GeneralRe: Why is it asking for username and password? Pin
jkleiss6-Mar-08 7:48
jkleiss6-Mar-08 7:48 
GeneralRemote execution does not complete Pin
mholzer5423-Nov-05 9:13
mholzer5423-Nov-05 9:13 
GeneralGreat utility, congratulations. Pin
lancer22719-Oct-05 0:37
lancer22719-Oct-05 0:37 
GeneralRe: Great utility, congratulations. Pin
ksshaan2-Jul-08 18:29
ksshaan2-Jul-08 18:29 
GeneralRe: Great utility, congratulations. Pin
jdixon227826-Mar-10 4:22
jdixon227826-Mar-10 4:22 
Generalgreat job and a question Pin
msmarlene15-Jul-05 8:25
msmarlene15-Jul-05 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.