这组命令运行不干净。它正确重命名但不加入域或将用户添加到本地组管理员。
@echo off
SET /P compName=Name of the computer:%=%
SET /P duName=Computer User:%=%
SET /P adminUserName=Admin UserName:%=%
SET /P adminPassword=Admin Password:%=%
echo If the Above information was entered incorrectly or is incorrect please exit this application now.
PAUSE
CLS
echo Renaming the computer %compName%.
wmic COMPUTERSYSTEM WHERE Name="%ComputerName%" CALL Rename Name="%compName%" Password=null UserName=null
PING 1.1.1.1 -n 1 -w 3000 > nul
echo Error Level: %errorlevel%
echo Joining the computer to the Doamin.net Domain.
wmic COMPUTERSYSTEM WHERE Name="%COMPUTERNAME%" CALL JoinDomainOrWorkgroup FJoinOptions=1 Name="Domain.net" UserName="%adminUserName%" Password="%adminPassword%"
echo Error Level: %errorlevel%
PING 1.1.1.1 -n 1 -w 3000 > nul
echo Adding %duName% to the Administrator's group.
net LOCALGROUP Administrators /ADD %duName%
echo Error Level: %errorlevel%
PING 1.1.1.1 -n 1 -w 3000 > nul
echo Restarting computer...
Shutdown /R /c "Restarting computer and applying changes."
但是,如果我用 PAUSE 替换 Ping 命令,它确实可以顺利通过。问题是我希望它自动化并且我不想使用不同的编码语言。我认为问题在于 WMIC 已经用于重命名并且 PAUSE 将其释放,然后它再次为域重新初始化然后当然添加到管理员组失败,因为它始终是域帐户,但我再次不确定。任何见解将不胜感激!