Renaming Remote Workstations using PSEXEC

Instructions:

  1. Your operator workstation needs to be Windows XP or better (only for the reboot function, Windows 2000 might work, but i never tested it)
  2. Create a folder called "rename"
  3. Put WSNAME.EXE and PSEXEC.EXE (www.sysinternals.com) into this folder along with the Batch file below (save as rrename.cmd)
  4. Shell out to a "CMD" prompt
  5. Navigate to your "rename" directory
  6. Enter rrename <target PC> <new name> <userid> <password> [reboot]

Note that the example below uses the "Rename in Domain" function so you need to provide credentials that have sufficient permission to rename the computer object within AD

%<------------ Cut below this line ------------

@echo off
if "%1" EQU "" GOTO SHOWSYNTAX
if "%2" EQU "" GOTO SHOWSYNTAX
if "%3" EQU "" GOTO SHOWSYNTAX
if "%4" EQU "" GOTO SHOWSYNTAX

if not exist wsname.exe GOTO SHOWSYNTAX
if not exist psexec.exe GOTO SHOWSYNTAX

if /i "%5" EQU "REBOOT" (
SET REBOOT=Y
) ELSE (
SET REBOOT=N
)

echo Connecting
net use \\%1\ipc$ > NUL
if NOT ERRORLEVEL == 0 GOTO NETERROR

echo Copying WSNAME locally
COPY WSNAME.EXE \\%1\C$ > NUL

echo Launching WSNAME
PSEXEC \\%1 C:\WSNAME.EXE /N:%2 /RCID /USER:%3 /PASS:%4
if "%ERRORLEVEL%" NEQ "0" SET REBOOT=N

echo Tidying Up
DEL \\%1\C$\WSNAME.EXE

echo Disconnecting
net use \\%1\ipc$ /d > NUL

if "%REBOOT%" EQU "Y" (
echo Rebooting '%2' so new the name will take effect
shutdown /m \\%1 /r /f /c "Rebooting so new name will take effect"
)

GOTO END

:NETERROR
echo.
echo ERROR: Could not connect to %1
echo.
GOTO END


:SHOWSYNTAX
echo.
echo Remote Rename in Domain
echo. Syntax: RemoteName "device existing name" "new name" "userid" "password" [REBOOT]
echo.
echo. Requires PSEXEC.EXE and WSNAME.EXE
echo.
echo. Get PSEXEC from www.sysinternals.com
echo.
echo.


:END
SET REBOOT=

 

%< ------------ Cut above this line ------------