1、加入域退出域的脚本 46100新装的电脑,我喜欢用 VBS,来实现,计算机名、IP、子网、网关、DNS、WINS 及域的自动加入。因为楼主的方法需要先装 SUPPOT 工具。感觉很麻烦。感觉脚本很方便:下面是我的脚本内容。不过各有各的好处。看大家选择。首先的脚本有两个 VBS 文件,一个是renamecomputer.vbs ,用于计算机名称; 二是 joindomain.vbs ,用于 IP、子网、网关、DNS、WINS 及域的加入.第一个脚本执行后,再执行第二个,脚本内容如下:1、renamecomputer.vbsstrComputerName = InputBox(“Please ty
2、pe your new computer name“,“Input“)strComputer = “.“Set objWMIService = GetObject(“winmgmts:“ _& “impersonationLevel=impersonate!“ & strComputer & “rootcimv2“)Set colComputers = objWMIService.ExecQuery _(“Select * from Win32_ComputerSystem“)For Each objComputer in colComputersstrErr = objComputer.Re
3、name(strComputername)NextIf strErr = 0 ThenSet objShell = CreateObject(“Wscript.shell“)Set fso = CreateObject(“Scripting.FileSystemObject“)fso.CopyFile “joindomain.vbs“,“c:windowssystem32“objshell.RegWrite “HKLMSOFTWAREMicrosoftWindowsCurrentVersionRunOncejoindomain“,“c:windowssystem32joindomain.vbs
4、“,“REG_SZ“return=MsgBox(“Yes for reboot,no for cancel.“,vbYesNo+vbInformation,“Information“)If return=6 Then objshell.Run(“cmd /c shutdown.exe -r -t 0“)End If2、joindomain.vbsConst JOIN_DOMAIN = 1Const ACCT_CREATE = 2Const ACCT_DELETE = 4Const WIN9X_UPGRADE = 16Const DOMAIN_JOIN_IF_JOINED = 32Const J
5、OIN_UNSECURE = 64Const MACHINE_PASSWORD_PASSED = 128Const DEFERRED_SPN_SET = 256Const INSTALL_INVOCATION = 262144strIPAddress = array(“10.15.1.40“)strIPAddress = array(InputBox(“Please type your IP address“,“Input“)strSubnetMask = array(“255.255.0.0“)strGateway = array(“10.15.0.253“)strGatewayMetric
6、 = array(“1“)strwinsOne = “10.15.0.1“strwinsTwo = “10.100.1.2“strdnsOne = InputBox(“Please type your first DNS address“,“Input“)strdnsOne = “10.15.0.1“strdnsTwo = InputBox(“Please type your second DNS address“,“Input“)strdnsTwo = “10.100.1.2“strDomain = InputBox(“Please type your domain name“,“Input
7、“)strDomain = ““strUser = InputBox(“Please type your domain user name“,“Input“)strUser = “lafferli“strPassword = InputBox(“Please type you domain users password“,“Input“)strComputer = “.“Set objShell = CreateObject(“Wscript.shell“)Set objWMIService = GetObject(“winmgmts:“ _& “impersonationLevel=impe
8、rsonate!“ & strComputer & “rootcimv2“)Set colNetCards = objWMIService.ExecQuery _(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True“)For Each objNetCard in colNetCardserrEnable = objNetCard.EnableStatic(strIPAddress,strSubnetMask)errGateways = objNetCard.SetGateways(strGateway,
9、strGatewayMetric)arrDNSServers = Array(strdnsone, strdnstwo)objNetCard.SetDNSServerSearchOrder(arrDNSServers)SetWins = objNetCard.SetWINSServer(strwinsOne,strwinsTwo)arrWINSServers = Array(strwinsOne, strwinsTwo)objNetCard.SetWINSServer strwinsOne,strwinsTwoobjNetCard.WINSPrimaryServer strwinsOneobj
10、NetCard.WINSSecondaryServer strwinsTwoNextSet objNet = CreateObject(“Wwork“)strComputerName = objnet.ComputerNameSet objComputer = GetObject(“winmgmts:impersonationLevel=Impersonate!“ & _strComputer & “rootcimv2:Win32_ComputerSystem.Name=“ & _strComputername & “)ReturnValue = objComputer.JoinDomainO
11、rWorkGroup(strDomain, _strPassword, strDomain & “ & strUser, NULL, _JOIN_DOMAIN + ACCT_CREATE)If returnvalue = 0 Thenreturn =MsgBox(“Now the script will reboot your computer.“,vbOKOnly+vbInformation,“Information“)If return = 1 Then objshell.Run(“cmd /c shutdown.exe -r -t 0“)End if3、此脚本执行时,会提示输入计算机名和 IP 地址及加入域时用到的用户的密码。IP 地址也可以事先写好。总结,如果是没有权限的用户登录,那么用此脚本加域或者退域是最好的方法。补充,只需要执行 renamecomputer.vbs 就可以了,第二个脚本会被调用执行。唯一需要做的就是根据提示,输入计算机名、要加入域的 PC 的 IP 地址、有加入域权限的用户密码。