Click here to Skip to main content
15,868,026 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.3K   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

 
AnswerRe: Problems in XP Pin
RM-Coder27-Feb-08 10:51
RM-Coder27-Feb-08 10:51 
GeneralName and User ID prompts Pin
mag14-Jun-04 9:07
mag14-Jun-04 9:07 
AnswerRe: Name and User ID prompts Pin
RM-Coder27-Feb-08 10:53
RM-Coder27-Feb-08 10:53 
GeneralAuthentication and Security Pin
aissakoo4-Jun-04 4:08
aissakoo4-Jun-04 4:08 
GeneralRe: Authentication and Security Pin
mag14-Jun-04 13:43
mag14-Jun-04 13:43 
GeneralRe: Authentication and Security Pin
aissakoo4-Jun-04 14:44
aissakoo4-Jun-04 14:44 
AnswerRe: Authentication and Security Pin
RM-Coder27-Feb-08 10:54
RM-Coder27-Feb-08 10:54 
QuestionRe: Authentication and Security Pin
girlpilot10-Jan-07 10:37
girlpilot10-Jan-07 10:37 
Did you ever add security to RexecService, or find a version that someone else did? I'd like to require a userid and password - before I modify the code myself, I thought I'd check to see if anyone else already did.

Thanks,
Sally Moritz
Generalsocket connection fails Pin
WPCP24-May-04 4:23
WPCP24-May-04 4:23 
GeneralRe: socket connection fails Pin
WPCP24-May-04 8:25
WPCP24-May-04 8:25 
Generalneed help Pin
Member 102627716-Apr-04 9:50
Member 102627716-Apr-04 9:50 
QuestionHow to executing MFC application in Limited account of Xp Home Operating System Pin
KumarRajeev26-Mar-04 18:38
KumarRajeev26-Mar-04 18:38 
AnswerRe: How to executing MFC application in Limited account of Xp Home Operating System Pin
Danish Shamim11-Sep-04 2:48
Danish Shamim11-Sep-04 2:48 
GeneralRe: How to executing MFC application in Limited account of Xp Home Operating System Pin
Rostik198031-Oct-06 8:21
Rostik198031-Oct-06 8:21 
GeneralNEED HELP!!!!!!!!!!!!!!!!!!!!! Pin
omega70815-Mar-04 4:20
omega70815-Mar-04 4:20 
Generalproblem with connection Pin
Anonymous12-Feb-04 18:58
Anonymous12-Feb-04 18:58 
GeneralRe: problem with connection Pin
Joffrey12-Mar-04 1:26
Joffrey12-Mar-04 1:26 
GeneralRe: problem with connection Pin
RUser015-Dec-05 2:41
RUser015-Dec-05 2:41 
GeneralRe: problem with connection Pin
Badci-Tox28-Feb-06 5:46
Badci-Tox28-Feb-06 5:46 
GeneralRe: problem with connection Pin
Dieter3-Dec-07 20:57
Dieter3-Dec-07 20:57 
AnswerRe: problem with connection Pin
RM-Coder27-Feb-08 10:56
RM-Coder27-Feb-08 10:56 
Generalsometimes, remote command is not launched Pin
Luc Lavayssiere20-Jan-04 4:12
Luc Lavayssiere20-Jan-04 4:12 
Generalnot getting service manager Pin
skpanda8-Jan-04 23:14
skpanda8-Jan-04 23:14 
GeneralSecurity Problem Pin
Member 65944131-Oct-03 9:58
Member 65944131-Oct-03 9:58 
GeneralRe: Security Problem Pin
mag15-Jun-04 10:52
mag15-Jun-04 10:52 

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.