Remote command execution on Windows 2003 server

commandremotewindows-server-2003

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…

Best Answer

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.
==================================
Related Topic