Reputation: 21
Background:
I am migrating several thousand computers from xp to 7 as a sub-contractor. The computers are on a domain. We have admin rights to add, modify and delete computers from the domain. When we first approach a xp machine, we have to add "delete" in front of the name and rename it (example: old name "pc12345" new name "deletepc12345"). I am working on a batch file that will help with this process, but I am running into some trouble.
Script:
@echo off
SET /P PCNAME=delete%computername%
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ /v ComputerName /t REG_SZ /d %PCNAME% /f
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ /v Hostname /t REG_SZ /d %PCNAME% /f
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ /v "NV Hostname" /t REG_SZ /d %PCNAME% /f
@echo off
echo Please Restart your computer Manually. The Program will exit now.
echo.
echo.
pause
Issue: After running the batch file. The computer name is changed to "/f" instead of the "deletepc12345"
Upvotes: 2
Views: 4556
Reputation: 17866
Remove the /p
from set /p PCNAME=...
. What that's doing is prompting the user for input and merely printing "delete%computername%" to the screen. What you want is simply
set "PCNAME=delete%computername%"
As it is now, probably PCNAME ends up being an empty string and /d %PCNAME% /f
is being evaluated as "/d /f".
If you change @echo off
to @echo on
, your script will print each line as it runs and you can see exactly what's being evaluated.
Upvotes: 1