找回密码
 加入
搜索
查看: 5464|回复: 1

[系统综合] 计算机改名并自动加域的实现

[复制链接]
发表于 2010-5-5 15:47:01 | 显示全部楼层 |阅读模式
最下边是一段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
发表于 2010-5-7 10:30:16 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 09:35 , Processed in 0.081197 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表