Click here to Skip to main content
15,889,343 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 338.6K   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

 
GeneralRe: NT service program swallow up all CPU resource Pin
Tim Kohler19-Jan-03 5:26
Tim Kohler19-Jan-03 5:26 
GeneralPsExec by SysInternals Pin
Thomas Freudenberg17-Jan-03 4:51
Thomas Freudenberg17-Jan-03 4:51 
GeneralRe: PsExec by SysInternals Pin
Paul Farry18-Jan-03 13:41
professionalPaul Farry18-Jan-03 13:41 
GeneralXCmd Pin
Lau19-Jan-03 16:16
Lau19-Jan-03 16:16 
GeneralRemote Execution Pin
Golden Lee16-Jan-03 21:55
Golden Lee16-Jan-03 21:55 
GeneralRe: Remote Execution Pin
Claudius Mokler16-Jan-03 23:19
Claudius Mokler16-Jan-03 23:19 
GeneralRe: Remote Execution Pin
JoMa17-Jan-03 2:17
JoMa17-Jan-03 2:17 
GeneralRe: Remote Execution Pin
Claudius Mokler17-Jan-03 2:33
Claudius Mokler17-Jan-03 2:33 
The original poster didn't mention that G: is a network drive.
I doubt it, since starting an installed windows application from a network drive doesn't seem too bright.

Since the service is installed with "allow service to interact with desktop" set, it invariably runs in a built-in account named LocalSystem.
Of course, LocalSystem doesn't know about some user's connected network drives;
it is well possible to use rexec to start a process when no user is logged on.
Here either UNC paths have to be used or a not-quite-secure batch file has to be maintained on the remote machine that looks like this:

net use g: \\server\share /user:domain\username password
g:\whatever\application.exe
net use g: /delete

Here a network drive is connected using impersonation, that is, the user credentials
domain, username and password are used.

This is not secure since the password has to be given in plain-text in the batch file. However, if that batchfile resides in a location that can't be accessed from the network, this might be considered.

Anyway, this applies only if the drive g: were a network drive in the first place.

I presume that the original poster misunderstood the concept of rexec, presuming (on his/her part) that the files being executed remain on a different machine than the remote machine on which the rexec service runs.

GeneralRe: Remote Execution Pin
aminorex19-Nov-03 6:36
aminorex19-Nov-03 6:36 
GeneralRe: Remote Execution Pin
Golden Lee18-Jan-03 17:00
Golden Lee18-Jan-03 17:00 

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.