remote command execution on Windows 2003 server

14,204

Solution 1

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

Solution 2

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.

Solution 3

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:
14,204
Steve Hawkins
Author by

Steve Hawkins

Updated on September 17, 2022

Comments

  • Steve Hawkins
    Steve Hawkins almost 2 years

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

    • JS.
      JS. about 15 years
      Which command are you trying to execute on the remote machine?
    • romandas
      romandas about 15 years
      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
      romandas about 15 years
      FWIW, I've never had trouble with psexec and Windows 2003.
    • Steve Hawkins
      Steve Hawkins about 15 years
      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
    Steve Hawkins about 15 years
    I added a comment to my original posting above. All suggestions are appreciated -- Thanks.
  • Steve Hawkins
    Steve Hawkins about 15 years
    See the note that I've added to my posting above.
  • aeroshock
    aeroshock about 15 years
    Amended my answer following your edit
  • Steve Hawkins
    Steve Hawkins about 15 years
    Thanks very much, your suggestion worked just fine. I really appreciate the advice.
  • aeroshock
    aeroshock about 15 years
    Glad it was useful :)