通过在当前计算机名称前添加批量重命名计算机 [英] Batch rename pc by prepending the current pc name

查看:45
本文介绍了通过在当前计算机名称前添加批量重命名计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

作为分包商,我正在将数千台计算机从XP迁移到7.这些计算机在域上.我们拥有从域中添加,修改和删除计算机的管理员权限.当我们第一次使用xp机器时,我们必须在名称前面添加删除"并重命名(例如:旧名称"pc12345"新名称"deletepc12345").我正在处理一个批处理文件,该文件将有助于完成此过程,但是我遇到了一些麻烦.

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.

脚本:

@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

问题:运行批处理文件后.计算机名称更改为"/f",而不是"deletepc12345"

Issue: After running the batch file. The computer name is changed to "/f" instead of the "deletepc12345"

推荐答案

set/p PCNAME = ... 中删除/p .这样做是在提示用户输入,仅在屏幕上打印"delete%computername%".您想要的只是

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%"

现在,可能PCNAME最终是一个空字符串,并且/d%PCNAME%/f 被评估为"/d/f".

As it is now, probably PCNAME ends up being an empty string and /d %PCNAME% /f is being evaluated as "/d /f".

如果将 @echo off 更改为 @echo on ,则脚本将在运行时打印每一行,并且您可以确切地看到正在评估的内容.

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.

这篇关于通过在当前计算机名称前添加批量重命名计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆