Click here to Skip to main content
Click here to Skip to main content

Executing programs remotely in Windows NT/2000/XP

By , 16 Jan 2003
 

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:

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:

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

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionsocket connection failedmemberMember 47689816 May '12 - 21:31 
I got the error socket connection failed
QuestionPSExec could be the solution to all of you that have problems.memberMember 820973731 Oct '11 - 8:51 
Hey, Friends.
I couldn't connect to RExecService using RExec. But PSExec did the trick OK.
And PSExec has a forum at Sysinternals website (inside Micro$oft site). This tool is inside the PSTools suite, programmed by Mark Russinovich.
Good luck.
Questionrexec is giving connection refusedmembermaestromani20 Sep '11 - 5:29 
Hi There,
 
Executed rexec ipaddress notepad, after giving user name and passwd (local account) i get below error
 
<pre lang="vb">&gt; rexec:connect:Connection refused
rexec: can&#39;t establish connection</pre>
 
No firewall.
AnswerRe: rexec is giving connection refusedmemberAZeitler13 Dec '11 - 10:20 
There is more than one rexec. Rexec also exists as a Windows command. You can read about that command here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/rexec.mspx?mfr=true[^]
 
The Windows version of rexec will prompt you for username and password, the version provided here does not. Because the Windows version exists within the system path, it will be called if you don't properly call the one provided here. If you have the copy provided here in the directory where you are calling rexec, then it will use that rexec. If you don't have it there, then it will call the Windows version. Both are similar, but there are differences (for one, this version doesn't seem to redirect standard output to the caller, but the Windows version does). Also, the Windows version requires username and password, whereas this one does not (thus an easy way to tell which one you are calling).
 
Double check and make sure that the directory you are calling rexec from has a copy of the rexec.exe from this site.
GeneralI have the program working locally on one windows xp pro machine but can't install service in windows 7memberStephane Poirier23 Aug '11 - 11:55 
I have the program working locally on one windows xp pro machine but can't install service in windows 7.
 
Anyone suceeded?
GeneralSuggestions for people who have problemsmemberjdixon227826 Mar '10 - 6:21 
For connection problems, make sure your firewall isn't blocking. Also, make sure the service is running and set to start up automatically.
 
For people having problems with running programs, start small. Pull up notepad on the remote computer without the parameter on the end. It should look something like this:
 
rexec 123.21.61.12 notepad.exe
 
If that pulls up notepad on the remote system, you are set. If you have problems with applications not running correctly, I suggest creating a batch file on the remote system that does pull up the application correctly. Once you get the program working through the batch file, you can use that to troubleshoot (maybe path/spelling was wrong, incorrect switches, etc). Or you could just use rexec to call the batch file and you are done.
 
Also to note, pulling up something from a direct path requires the path to be in quotes. Example:
 
rexec 10.1.1.151 "c:\test.exe"
Question'Local System' can't access network share foldermemberSekhar Kumar5 May '08 - 6:37 
Hello,
Can I specify User name to start the service rexecService.exe ? Default user name is 'Local System' and that's the reason I'm not able to access share folder in other machine.
 
I have a folder shared on a machine A running windows server XP with read & Write access to everyone. On machine B i have a windows service(rexecService.exe) running under LocalSystem Account. The service (in m/c B)is not able to access the files in the shared folder inspite of having set read write access to everyone.
 
However, I can access the shared folder in A as an Administrator of machine B. Please help me in this regard.
Thanks in advance.
Generalruntime to terminatememberkalle10 Dec '07 - 5:46 
I get this message when i run the program.
rexec.exe 192.168.xxx.xxx c:\notepad.exe
 
"This application has requested the runtime to terminate it in an unusual way.
Please contact the application´s support team for more information."
 
Whats wrong?
GeneralSocket Connection Failedmemberyug_chary12 Oct '07 - 1:12 
When i tried to run the program remotely, "Socket Connection Failed" error message is dispalyed. Can anyone please help me out.
 
Yugandher
GeneralRe: Socket Connection FailedmemberEli Hazan27 Mar '08 - 11:07 
I get the same error, anyone know how to fix this?
GeneralRe: Socket Connection Failedmembervipul052719 Nov '09 - 18:11 
I also got the same error
GeneralRe: Socket Connection Failedmembernax2283 May '10 - 23:53 
Most likely you have not started the service on client PC. Could be a firewall issue as well.
NAX

GeneralRe: Socket Connection Failedmemberxytsrm22 Jan '11 - 4:04 
Most important you must enter "rexecservice" in the firewall exceptions for the PC running the service.
 
I installed the service on and "XP Home" PC following the instructions.
 
I ran "rexec" on a Vista PC on the network and got the "Socket Connection Failed".
 
I entered the service into the firewall exeptions and ran rexec again - bingo it worked perfectly.
GeneralImprovment issuesmemberElad raz14 Mar '07 - 1:50 
Hi.
 
I think it will be greate if you could add synchonious execution. E.g. the rexec process will wait until the remote process will terminate.
 

 
Elad Raz
CTO,
RazTech
http://www.raztech.co.il

Generaloutputmembersdev4003 Jan '07 - 13:39 
Is it possible to capture the output of a program run remotely with rexec?
 
sdev400

GeneralRemote execution does not workmemberautoguy10011 May '06 - 3:42 
Any one has sucess in using this. I am getting error as connection refused.
QuestionWhy is it asking for username and password?memberlearningvisual5 Apr '06 - 12:49 
When I run "rexec ip app" I am getting a "Name (ip:username)", I type a username and then is asking me for a "Password (ip:username)", I type the password and finally I get an error ">rexec:connect:Connection refused" next line "rexec: can't establish connection".
 
If anyone can help me I will really appreciate it.
 
José
AnswerRe: Why is it asking for username and password?memberjkleiss25 Sep '06 - 10:11 
I had the same problem. Two things I did fixed this problem (I'm not sure what's necessary, but doing them both fixed my problem)
terminology: server computer wants to submit a program for remote execution on a client computer.
1) I had followed the CLIENT computer instructions on the SERVER computer. (running rexecServices -i, and changing settings in services manager). I undid these steps. (Right-click "Remote program Execution," and select "stop," and delete rexecService folder entirely, just to be sure)
 
2) The Server computer must be in the folder where you unzipped the rexec.exe program. If you're in any other folder, it will run, but will ask for username and password.
 
Good luck!
 
Jessica
AnswerRe: Why is it asking for username and password?memberBlades6 Mar '08 - 6:21 
Hi Jessica,
 
Did you get rexec to run ok? I am a bit confused on the steps you posted. I am still getting the username and password.
 
Thanks
 
William
 
B_L_A_D_E_S@hotmail.com
GeneralRe: Why is it asking for username and password?memberjkleiss6 Mar '08 - 7:48 
Hi William,
 
Sorry for the confusing steps. Looking back on it, I suggest you ignore my "step 1" Clearly I was just confused, making mistakes, and then undoing them. One would hope this doesn't affect the program's execution. In which case the only suggestion I have to offer you is my "step 2"
 
I didn't end up using rexec in the long-run, and this message was a long time ago, so I really don't have any other useful advice to offer you now. Sorry. Anyone else out there?
 
-Jessica
GeneralRemote execution does not completemembermholzer5423 Nov '05 - 9:13 
I am trying to remotely execute a program called Printwiz and it just hangs in the DOS window. Any ideas?
 
Thanks,
 
Marc Holzer

GeneralGreat utility, congratulations.memberlancer22719 Oct '05 - 0:37 
Thanks for this great utility, very useful! Wink | ;)
GeneralRe: Great utility, congratulations.memberksshaan2 Jul '08 - 18:29 
Fantastic Smile | :)
It resolved issues .Thanks A lot
GeneralRe: Great utility, congratulations.memberjdixon227826 Mar '10 - 4:22 
I also want to say this is a great utility. I have tried a few of the famous ones and couldn't get any of them to work. This thing worked perfectly the very first time! My gratitude to the author.
Generalgreat job and a questionmembermsmarlene15 Jul '05 - 8:25 
Are there other hidden options for rexecServer.exe besides -i?
I would like the server process to use a login other than system. Is this supported?
 
marlene
 
I take back the good job part. This server is not dependable at all. I just tried to bring up notepad and it didn't succeed. Now it only succeeds about every 7 to 8 attempts.
GeneralPlease help me!memberdSolariuM14 Jul '05 - 21:08 
Hi,
Very good and useful but you said that:
 
Note that for this to work properly, the remote execution service must be installed and started on the machine @ 123.21.61.12
 
I don't want it.I want a code to run an exe file remotely without any client program.
 
Please help me,
Cheers,
MILAD.
 
Every new thing you learn,Gives you a new personality.
GeneralGreat Job!memberJames White16 May '05 - 11:06 
I've been waiting for this sort of thing for a while (don't know why it never occured to me to build it), great work!
General30258D71-1170-4923-B320-A14480854B1F.txtmembermacorc13 Dec '04 - 22:45 
Another thing happening ...
 
Sometimes (quite often), when I start rmtcmd to execute (notepad, for instance) I get the following error:
 
"The process can not access the file '\\machine\c$\30258D71-1170-4923-B320-A14480854B1F.txt' because it is being used vy another process.
 
Any ideas how to fix this?
 
thanks
GeneralNo reactionmembermacorc13 Dec '04 - 2:06 
Hi,
 
I downloaded this application, put the rexecService in the remote computer, register it, I made sure the option "Allow service to interact with desktop" was checked, ...
 
Then I execute the rexec in my local computer ... rexec IP notepad.exe ... and I didn't get any error, but when I go to the remote computer notepad is not visible and there is no process running with the name notepad.exe.
 
The funny thing is, when I install the service in my own local computer and try to do the same (from local computer to local computer) notepad is not visible either, but when I check the list of processes I can see as many instances of it as times I used the remote service.
 
Any guesses about what happens?
 
thanks
GeneralRe: No reactionmemberMember 939721531 Aug '12 - 10:56 
Having same issue. Please help.
GeneralRunning vbs script on remote computermemberjsvalois@excite.com11 Sep '04 - 9:09 
Hi,
 
I can use the program to launch executable files on remote machines, but I can't start vbs scripts using it. Any idea why not?
GeneralRe: Running vbs script on remote computermemberPrashant S. Patali25 Nov '04 - 16:59 
To solve your issue, try the following :
 
rexec "machineip" cmd "cscript xyz.vbs vbscript parameters"
 
Basically the VBS is executed by the cscript engine and you cannot execute it directly from a remote machine, so you take this alternative.
 
Let me know if you are still facing the problem.
 

 
Regards,
Prashant
GeneralCannot start multiple threads from a remotely executed programmemberepiieq129 Jul '04 - 14:55 
Hey all. I'm working in an office and have to do some testing that requires me to launch multiple instances of a program at once. I've managed to successfully use the rexec service with these computers. I've written a little exe that is run on the remote machine exe with command line arguments to start the program I need multiple times. The problem is, when I remotely execute, it will only start one instance and ignores my registry edit. Is there a built in function that stops multiple programs from being spawned? If so, is there a way for me to get rid of it? Thanks! Smile | :)
GeneralProblems in XPmemberclive10021 Jul '04 - 4:40 
I notice that many member have managed to get this working, but I am have problems !!
 
I have run the service with the -i option, gone to the services manager and marked the service for interaction with the desktop.
 
Whebn I try and start the service it keeps saying
 
Could not start the Remote Program Execution serice on loacal computer
Error 1317 : The specified user does not exist
 

I have tried different user accounts but always the same !
 
Any body help ?
GeneralRe: Problems in XPmemberbazzelle19 Aug '04 - 7:29 
Yes, copy the install files to the local machine before installing. Since you installed it now though, you will need to take a few extra steps. 1st copy the files to the local machine. 2nd open regedit (make backup of reg.. bla, bla..) go to hkey_LM\system\currentcontrolset\services\remoteexecutionservice and change imagepath to the location on local machine. Give that a shot and let me know if it worked for you or not.
 

AnswerRe: Problems in XPmemberRM_Coder27 Feb '08 - 10:51 
I found out Windows XP has its own REXEC command in CMD shell. I spent some time trying to get it runing, until I ran ethereal sniffer , and saw it was using different sockets. , I switched to the client side tools folder and ran the cmd from there , that works. The windows REXEC cmd has different syntax
type REXEC /? to see if windows syntax response . If response is socket connection failed you are using the correct client. If response is help for user and null redirect options etc. Is not this client 8)
GeneralName and User ID promptsmembermag14 Jun '04 - 9:07 
I am trying to use rexec to remote startup a application exe on
a remote machine, but I am being prompted for Name and UserID, After
insert network id and pw still wont fire the exe on the remote machine.
 
Is there a setting to keep from being promted for name and pw?
 
Any help would be appreciated..........
AnswerRe: Name and User ID promptsmemberRM_Coder27 Feb '08 - 10:53 
See response to other posting for problems nder Windows XP.
GeneralAuthentication and Securitymemberaissakoo4 Jun '04 - 4:08 
I've just started using RexecService and it works great however I need to know if it's possible to add some security to it. Similar to MS-Telnet's NTLM authentication. Otherwise it poses a big problrm for us because I'd like to install the service on all the my machines across our network.
 
Any feedback would be appreciated. I don't know C++ that well but with some help I'd be willing to work with someone to add some security to the current code By Tim Kohler.
 
Thanks
 
Alex Issakoo
GeneralRe: Authentication and Securitymembermag14 Jun '04 - 13:43 
I have also just started using RexecService and was wondering if
you had a problem with being prompted for a name and userid when
running rexec.
 
If so how did you handle.....Mike
GeneralRe: Authentication and Securitymemberaissakoo4 Jun '04 - 14:44 
No I followed the directions and it worked like a charm however I did see the username and password option but I think that's to install the service only. Plus after looking at the code, once again I'm not a pro but I don't see anything relating to security.
AnswerRe: Authentication and SecuritymemberRM_Coder27 Feb '08 - 10:54 
See answer under Problems in Windows XP posting above.
QuestionRe: Authentication and Securitymembergirlpilot10 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 failsmemberWPCP24 May '04 - 4:23 
When I attempt to execute program on remote machine, I get a message "Socket connection failed".
Any ideas what's wrong?
 
System is a wireless network, with all drives shared on peer to peer. Installation of service went well on remote machine.

GeneralRe: socket connection failsmemberWPCP24 May '04 - 8:25 
Original author of socket connection fails....
 
I found the problem. After installation of service on remote machine, service had to be started. Program worked fantastically after that little glitch.
Generalneed helpmemberjosephboban16 Apr '04 - 9:50 
how to run windows scandisk in a project ie,when i click a button the scandisk should work,and when i cancel the control should come back the prog: and execute the remaining dialogues,if possible the scandik should start doing the mentioned drive on initialization of scandisk itself!! how do dooooBlush | :O
 
bob
QuestionHow to executing MFC application in Limited account of Xp Home Operating SystemsussRajeev Kumat26 Mar '04 - 18:38 
My Application need some file read,write rights for execution. We are creating some ini files. How to allow execution of application when we are using Limited account in Windows XP home.
AnswerRe: How to executing MFC application in Limited account of Xp Home Operating SystemsussDanishShamim8111 Sep '04 - 2:48 
Try assigning security rights for that folder to everyone and allowing everyone to read write permissions, we had a similar problem running a scanner program in limited accounts
GeneralRe: How to executing MFC application in Limited account of Xp Home Operating SystemmemberRostik198031 Oct '06 - 8:21 
i suggest that you create a local user and execute through that user rights
GeneralNEED HELP!!!!!!!!!!!!!!!!!!!!!memberomega70815 Mar '04 - 4:20 
Is there anyway to use REXEC from UNIX to Windows? I need to fire a script on an 2k Server from AIX 5.1. It seems that this software only works from Windows to Windows... AIX comes preloaded with REXEC from OS390 to UNIX, UNIX to UNIX and UNIX to OS390. But that doesn't help me much.....
 
-omega

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 17 Jan 2003
Article Copyright 2003 by Tim Kohler
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid