复制以下脚本保存后缀名为VBS,在客户端双击使用,使用前请修改红色文字为实际环境参数;
注:本脚本仅适用于WinXP,部分WIN7系统不适用。
=========================我是分隔线=========================
wscript.echo "在操作之前请保存好正在编辑的文件并切换到管理员权限下执行"
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "contoso.com"
strPassword = "Passw0rd"
strUser = "joindomain"
strou = InputBox("请输入对应分公司的OU名称","OU名称请在相应文档中查找")
strComputer = "."
Set objShell = CreateObject("Wscript.shell")
Set objNet = CreateObject("Wscript.network")
strComputerName = objnet.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputername & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "\" & strUser, "ou=" & strou & ",OU=test,dc=contoso,dc=com ", _
JOIN_DOMAIN + ACCT_CREATE)
If returnvalue = 0 Then
return =MsgBox("加域成功!即将重启您的计算机,点击确定立即重启!",vbOKOnly+vbInformation,"Information")
If return = 1 Then objshell.Run("cmd /c shutdown.exe -r -t 0")
End if
=========================我是分隔线=========================
转载于:https://blog.51cto.com/xiaowz/940958