7

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...

4
  • Which command are you trying to execute on the remote machine?
    – JS.
    Jun 26, 2009 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, 2009 at 18:03
  • FWIW, I've never had trouble with psexec and Windows 2003.
    – romandas
    Jun 27, 2009 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. Jun 27, 2009 at 18:10

8 Answers 8

8

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.
==================================
4
  • I added a comment to my original posting above. All suggestions are appreciated -- Thanks. Jun 27, 2009 at 3:43
  • Amended my answer following your edit
    – Izzy
    Jun 29, 2009 at 20:08
  • Thanks very much, your suggestion worked just fine. I really appreciate the advice. Jun 30, 2009 at 2:31
  • Glad it was useful :)
    – Izzy
    Jun 30, 2009 at 3:57
3

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.

2

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.

0

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.

0

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

0

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.

1
  • See the note that I've added to my posting above. Jun 27, 2009 at 6:40
0

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

-1

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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