Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a single command that I would like to execute on a remote Windows 2003 server.

I have tried wmic, which works, but the only way to display standard output is to redirect it to a local file, then list the local file (kind of clunky).

I have also tried psexec, but that seems to have problems working with Windows 2003 servers (at least its reported that the latest version does -- and older versions are not available).

I was trying to stay away from the Windows rcmd utility because I believe that there is a server component that would need to be installed, and I did not want to provide general command line access to the machine.

Are there any other suggestions for tools or utilities that would allow me to specific commands on a remote machine.

Note:

Here's a very simple example that I was using in an attempt to get PsExec to work:

C:\Program Files\SysInternalsSuite>psexec \\remote-svr -i -u MyUsername D:\Public\do.bat

PsExec v1.95 - Execute processes remotely
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com

Password:

D:\Public\do.bat exited on remote-svr with error code 1.

My sample do.bat file is trivial and contains just the following line:

copy dg.bmp dg1.bmp

The source file dg.bmp is present on the remote machine, the destination file is not. I do have write access to the remote machine.

When I execute the above PsExec command, the do.bat file does not run (although I do have privileges on the remote server) and I don't get the output to the console that I was expecting. I do like the idea of using PsExec, so if there are any tips on what I might be doing wrong, I would appreciate hearing them.

Thanks...

share|improve this question
    
Which command are you trying to execute on the remote machine? –  JS. Jun 26 '09 at 22:02
    
Any command within your do.bat file that fails will cause it to exit with an error code > 0. I suspect the do.bat is running, but something in it isn't working correctly. Can you show us that file? –  romandas Jun 27 '09 at 18:03
    
FWIW, I've never had trouble with psexec and Windows 2003. –  romandas Jun 27 '09 at 18:03
    
I just have one line in the do.bat file (copy dg.bmp dg1.bmp). I'm just trying to prove I can do something simple remotely with PSExec. –  Steve Hawkins Jun 27 '09 at 18:10

8 Answers 8

up vote 7 down vote accepted

What problems are you having with PSExec and W2k3 exactly? We use the two together extensively, in a 500+ W2k3 server environment...

In fact, the whole PSTools suite rocks my world.

EDIT:

This is a followup to your edit of the original ticket.

The problem you're encountering is that "copy" is a function of CMD.exe. It doesn't exist as its own executable in its own right. Same as there is no Del.exe, or MD.exe etc.

If you want your example to work you need to invoke CMD via PSexec, and pass the copy command to that. Here's an example:

psexec -u MyDomain\MyUsername -p MyPassword \\MyServer cmd.exe /c copy c:\sys\util\monitor_localhost.bat blah.bat

The result is as follows:

==================================
PsExec v1.86 - Execute processes remotely Copyright (C) 2001-2007 Mark Russinovich Sysinternals - www.sysinternals.com

1 file(s) copied. cmd.exe exited on fcgwnt53 with error code 0.
==================================
share|improve this answer
    
I added a comment to my original posting above. All suggestions are appreciated -- Thanks. –  Steve Hawkins Jun 27 '09 at 3:43
    
Amended my answer following your edit –  Izzy Jun 29 '09 at 20:08
    
Thanks very much, your suggestion worked just fine. I really appreciate the advice. –  Steve Hawkins Jun 30 '09 at 2:31
    
Glad it was useful :) –  Izzy Jun 30 '09 at 3:57

Admin Arsenal allow you to execute remote commands to one, some, or all of your windows systems. It's free to try.

After you select which computer(s) to execute your command on, simply select Tools -> Remote Command and you're on your way.

share|improve this answer

The way to execute command remotely in a windows environment is with Winrm and WINrs. See How to enable Windows Remote Shell and How WinRM & WinRS can help you, how to enable then, and examples of how you can use them.

share|improve this answer

Standard commands can be executed through telnet which its disabled on all Microsoft Workstations by default, but can be enabled through GPO and adding a user to the 'Telnet users' object group. This should suffice for most system commands.

share|improve this answer

You might want to try the "-c" option for psexec. It will copy the file to the remote system and then execute it, otherwise, it will expect it to be present on the remote system. So something like(copy the do.bat to the local system's c: and then):

psexec -c \remote-svr -i -u MyUsername c:\do.bat

Also, why do you want this to interact with the remote system's desktop session(the -i option)?

hth, ~H

share|improve this answer

Your generic command assumes that do.bat is locally present on remote server at specified location. If that is not the case then you can ask psexec.exe to copy file from your local machine to remote machine using -C option and then run it.

Also as pointed out if you are not doing anything interactive stuff with script do not include -I option.

I have tried beyondexec.exe, it is a good replacement for psexec.exe.

But I prefer psexec.exe as it is now provided thru Microsoft, so it is easier to justify its existence on servers to security hawks.

share|improve this answer
    
See the note that I've added to my posting above. –  Steve Hawkins Jun 27 '09 at 6:40

I could be wrong, but doesnt PS 2.0 allow remote commands and PS 1.0 local only?

share|improve this answer

I can't say I've ever tried this on a Windows machine but on Linux you can restrict the commands that ssh can execute via the use of the Authprogs script.

I put the HP version of ssh on most of my Windows systems for remote command line use. I've found it to be pretty easy to install compared to some of the other distributions of ssh for Windows out there. Google "SP25021" to find the HP provided installer.

I'm sure there are much newer versions of sshd for Windows available. I would advise using the latest possible version if your systems are not behind some serious firewalls.

See: Restricting SSH commands http://www.cmdln.org/2008/02/11/restricting-ssh-commands/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.