1: Const JOIN_DOMAIN = 1
2: Const ACCT_CREATE = 2
3:
4: strdnsOne = "192.168.100.1"'InputBox("Please type your first DNS address","Input")
5: strdnsTwo = "192.168.100.2"'InputBox("Please type your second DNS address","Input")
6: strDomain = "contoso.com"'InputBox("Please type your domain name","Input")
7: strUser = "administrator"'InputBox("Please type your domain user name","Input")
8: strPassword = "abcd@123"'InputBox("Please type you domain user's password","Input")
9:
10: strComputer = "."
11:
12: Set objShell = CreateObject("Wscript.shell")
13: Set objFSO = CreateObject("Scripting.FileSystemObject")
14:
15: Set objWMIService = GetObject("winmgmts:" _
16: & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
17:
18: Set colNetCards = objWMIService.ExecQuery _
19: ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
20:
21: For Each objNetCard in colNetCards
22: arrDNSServers = Array(strdnsone, strdnstwo)
23: objNetCard.SetDNSServerSearchOrder(arrDNSServers)
24: Next
25:
26: Set objNet = CreateObject("Wscript.network")
27: strComputerName = objnet.ComputerName
28:
29: Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
30: strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
31: strComputername & "'")
32:
33: ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
34: strPassword, strDomain & "\" & strUser, NULL, _
35: JOIN_DOMAIN + ACCT_CREATE)
36:
37: If ReturnValue = 0 Then
38: Set objCMD = objshell.Exec("c:\windows\system32\moveuser.bat")
39: Do While objCMD.Status = 0
40: WScript.Sleep 500
41: Loop
42: MsgBox "单击确定重新启动计算机",vbOKOnly+vbInformation,"信息"
43: objshell.Run("cmd /c shutdown.exe -r -t 0")
44: End If