您好我想更改新计算机的主机名值但事情不起作用,因为我尝试输入值并获取主机名的值。我尝试重新启动计算机,结果仍然相同..我正在测试这个脚本是否能够更新pcs或计算机名称的主机名
感谢
这是我的代码
REM This script runs in MS-DOS Batch File Language
@echo off
set /p id= Enter ID or Hostname:
echo %id%
WMIC computersystem where caption='%ComputerName%' rename %id%
REM exit the applications
echo "Export completed successfully. Press any key to exit"
pause >nul
exit /B
答案 0 :(得分:2)
以下我可能会这样做:
@Echo Off
Echo Your current name is %ComputerName%
:AskID
Set "ID="
Set /P "ID=Enter your new name: "
If Not Defined ID (Echo Can not be empty
GoTo AskID)
If /I "%ID%"=="%ComputerName%" Exit /B
If "%ID:~,1%"=="." (Echo Must not begin with a period
GoTo AskID)
Rem Put here some more checks for disallowed words or characters
WMIC ComputerSystem Where Name="%ComputerName%" Call Rename "%ID%"
<强> 备注 强>
Rem
arked line的建议。答案 1 :(得分:0)
我测试了以下批处理脚本,以通过批处理脚本更改Windows 10主机名,并且可以正常运行,请尝试一下并最后重新启动系统!
set /p NEW_NAME="Please enter computer name: "
for /f %%i in ('hostname') do set OLD_NAME=%%i
echo %OLD_NAME%
echo %NEW_NAME%
WMIC computersystem where caption="%OLD_NAME%" rename "%NEW_NAME%"
pause