最下边是一段VBS实现的计算机改名并自动加域的例子,我在将其转换到AU3: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
;将现有计算机改名为zgtestauto
$strComputername="zgtestauto"
$Servicetestxf = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colComputers = $Servicetestxf.ExecQuery ("Select * from Win32_ComputerSystem")
FOR $objComputer in $colComputers
$objComputer.Rename($strComputername)
NEXT
;将现有计算机加到yu.com域里
$strDomain = "yu.com"
$strUser = "test-user"
$strPassword = "test-password"
$strComputer = "."
$objNet = ObjGet("Wscript.network")
$strComputerName = $objNet.ComputerName
$objComputer = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\" & $strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & $strComputername & "'")
$ReturnValue = $objComputer.JoinDomainOrWorkGroup($strDomain,$strPassword, $strDomain & "" & $strUser, "", $JOIN_DOMAIN + $ACCT_CREATE)
If $ReturnValue=0 Then
MsgBox(64,"test","ok")
EndIf
时,不知达到效果,几经检查,无果。特向高手们求助~~~无比感激。
vbs脚本:strNewname = "zgtestauto"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = ObjComputer.Rename(strNewname)
Wscript.Echo err
Next
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 = "yu.com"
strUser = "test-user"
strPassword = "test-password"
strComputer = "."
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, NULL, _
JOIN_DOMAIN + ACCT_CREATE)
If returnvalue = 0 Then
return =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 if
|