JSI Tip 2476. How do I script an install, execution, and removal of the Remote Command Service?

In tip 1951 - "How do I install the Remote Command Service, remotely?",
I used tools from the Server Resource Kit and Supplement 4, to remotely install the Remote Command Service.

David A. Stewart, MCSE - Systems Administrator/RL-ATD/Eastman Kodak Co. - [email protected]
has provided a method to install, execute, and remove the service,
if you have security concerns with leaving it in place.

OpenRCMD.BAT uses Sc.exe, Rcmd.exe, Rcmdsvc.exe, and Oemnsvrc.inf
from the Server Resource Kit and Supplement 4

Usage: OpenRCMD

where ComputerName is the NetBIOS name of the remote computer.

OpenRCMD.BAT contains:

If \{%1\}==\{\} @echo computer name is required.&goto verybottom
set computer=%1
if not exist \\%computer%\admin$\system32\*.* @echo computer name is invalid or unavailable&goto verybottom
REM *** Display current variable settings ***
echo Current Computer is %computer%.
REM Install and start the Remote Command Server
set error=none
set tempa=
set rsystemroot=
FOR /F "skip=1 delims=    tokens=1-3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot" \\%computer%') do set tempa=%%c
FOR /F "tokens=1" %%a in ('@echo %tempa%') do set rsystemroot=%%a
xcopy Oemnsvrc.inf \\%computer%\admin$\system32xcopy Rcmdsvc.exe \\%computer%\admin$\system32echo.
If not exist \\%computer%\admin$\system32\Oemnsvrc.inf echo "Errored processing."
If not exist \\%computer%\admin$\system32\Oemnsvrc.inf goto verybottom
If not exist \\%computer%\admin$\system32\Rcmdsvc.exe echo "Errored processing."
If not exist \\%computer%\admin$\system32\Rcmdsvc.exe goto verybottom
SC \\%computer% CREATE RemoteCmd binpath= %rsystemroot%\system32\Rcmdsvc.exe START= Demand TYPE= own DEPEND= LanmanServer DisplayName= "Remote Command Server"
SC \\%computer% START RemoteCmd
Rcmd \\%computer%
REM Stop and remove the Remote Command Server
SC \\%computer% STOP RemoteCmd
timeout 5
SC \\%computer% DELETE RemoteCmd
del \\%computer%\admin$\system32\Oemnsvrc.inf
del \\%computer%\admin$\system32\Rcmdsvc.exe

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.