1

这组命令运行不干净。它正确重命名但不加入域或将用户添加到本地组管理员。

@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 将其释放,然后它再次为域重新初始化然后当然添加到管理员组失败,因为它始终是域帐户,但我再次不确定。任何见解将不胜感激!

4

3 回答 3

0

In my opinion it will be much easier if you use powershell instead of bat file. To add computer to domain you can use examples from http://letitknow.wordpress.com/2011/02/12/domain-join-using-powershell-v2-0-part-i/. To add user to local admin group üyou can use this one http://gallery.technet.microsoft.com/scriptcenter/Add-AD-UserGroup-to-Local-fe5e9239

于 2013-04-25T19:01:01.247 回答
0

首先你应该使用

ping -n 1 1.1.1.1 > Nul 

只需将 -n 1 更改为您想要等待的秒数。选项应该在目标之前,但这只是语义问题

如果您认为 WMIC 行导致问题,请将其替换为 NETDOM 命令。它更容易使用。

于 2013-04-25T19:06:28.060 回答
0

我建议完全更改wmicstart /wait "" wmic删除 PING。

于 2013-04-25T19:06:08.510 回答