加域腳本

  1. 編寫BAT文件:

@echo off
cd /
WSCRIPT //E:vbscript test.vbs
echo


2. 編寫VBS腳本


Option Explicit

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

Dim objNetwork,strComputer,strDomain,strPassword,strAdminUser,strOU,ReturnValue,objComputer
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
 
strDomain = "域"
strPassword = "密碼"
strAdminUser = "用戶名"
strOU = "OU=計算機,OU=XXX,OU=XXX,DC=XXX,DC=XXX"
Set objComputer = GetObject("winmgmts:{authenticationLevel=pktPrivacy,impersonationLevel=Impersonate}!\\" & _
     strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
        strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
     strPassword, strDomain & "\" & strAdminUser,strOU, JOIN_DOMAIN + ACCT_CREATE)
         
    If ReturnValue = 0 Then
    CALL AddDomainUsertoLocalAdmins
   ElseIf ReturnValue = 5 Then
    MsgBox "Access Denied, Please check the account to see if this account has permission",True
   ElseIf ReturnValue = 2691 Then
    MsgBox  "This Machin is already joined to a domain",True
   ElseIf ReturnValue = 1355 Then
    msgbox "The Sepicifed can not be contacted, please check your network or DNS settings",True
   ElseIf ReturnValue = 1398 Then
    msgbox "The time of computer is not correct with the Domain Controller, please correct the time",True
   ElseIf ReturnValue = 1311 Then
    msgbox "Can not find the Domain Controller, please make sure if there is a Domain controller",True
   ElseIf ReturnValue = 8557 Then
    msgbox "The User has joined so many computers that he has exceeded tht default per user computer quota",True
   Else
    msgbox "Error - Failed to Join Domain, the Error code is " & ReturnValue,True
   End If
         

Function AddDomainUsertoLocalAdmins

Dim objAdmins,LocalComputerName,UserAccountPath,UserAccount,domainname,Exec

domainname="XXXX.COM.CN"

End Function

  
WScript.Echo "成功! 請手動重啓計算機使用XXX域用戶登錄!"



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章