呕心沥血加域脚本 -2

转贴自http://hi.baidu.com/mikeoldyang/blog/item/5df0154b91784f2b08f7efdc.html

http://hi.baidu.com/mikeoldyang/blog/item/1ffce339608b46cad46225d3.html

 

' ----------------------------------------------------------------------------
' JoinDomainForIT.vbs
' VBScript program to Join computer into domain or rename it in the AD
' Date: 08/12/2008
' Version: 5.0 -- Change to Unicode and add chinese description.
' By: Mike Yang at AMD Suzhou 37890
' ----------------------------------------------------------------------------

On Error Resume Next

' ###########################################################################
' Get privilege account, e.g admin_xxx or acct_xxx
' ###########################################################################

' Dim Shell
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")

' -------------------------
' Get User & Password
' -------------------------
Set objExplorer = WScript.CreateObject _
    ("InternetExplorer.Application", "IE_")

objExplorer.Navigate "file:/ssuzfile22/helpdesk$/JoinDomain/Password.htm"  
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 620
objExplorer.Height = 420
objExplorer.Left = 100
objExplorer.Top = 100
objExplorer.Visible = 1            

Do While (objExplorer.Document.Body.All.OKClicked.Value = "")
    Wscript.Sleep 250                
Loop

' --------------------------------------------------------------
strUserName = objExplorer.Document.Body.All.UserName.Value
strUser = "amd/" & strUserName
strPassword = objExplorer.Document.Body.All.UserPassword.Value
' --------------------------------------------------------------

strButton = objExplorer.Document.Body.All.OKClicked.Value
objExplorer.Quit
Wscript.Sleep 250

If strButton = "Cancelled" Then
Wscript.Quit
End If
If strUsername = "" or strPassword = "" Then
Wscript.Quit
End If

' -------------------------
' Check input User
' -------------------------
adminxxx = Left(strUser,10)
'Wscript.echo adminxxx

acctxxx = Left(strUser,9)
'Wscript.echo acctxxx

If adminxxx <> "amd/admin_" and acctxxx <> "amd/acct_" Then
Wscript.echo "" _
   & "Error!! You must use acct_xxx or admin_xxx to run the tools. " & chr(10) & chr(13) _
   & "错误!!请使用acct或admin帐号来运行此工具 " & chr(10) & chr(13) & chr(10) & chr(13) _
   & "And you must use minuscule to inpute,like acct_yjay , please input again."& chr(10) & chr(13) _
   & "同时请务必使用小写来输入,比如 acct_yjay, 请再次输入。"

run8 = "//ssuzfile22/helpdesk$/joindomain/JoinDomainForIT.vbe"
'Wscript.echo run8
oShell.run run8,true
Wscript.quit
End If

' -------------------------
' Authenticate User
' -------------------------

Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_USE_ENCRYPTION = 2

strPath = "OU=Suzhou,dc=amd,dc=com"

Set root = GetObject("LDAP:")
Set objOU = root.OpenDSObject("LDAP://SSUZDC3/" & strPath, strUser, strPassword, _
        ADS_USE_ENCRYPTION AND ADS_SECURE_AUTHENTICATION)

SuzDN = objOU.distinguishedName
If err = 424 then
Wscript.echo "" _
   & "Logon failure: unknown user name or bad password, please input again." & chr(10) & chr(13) & chr(10) & chr(13) _
   & "登录失败,错误的用户名或者密码,请再次输入。"

run8 = "//ssuzfile22/helpdesk$/joindomain/JoinDomainForIT.vbe"
'Wscript.echo run8
oShell.run run8,true
wscript.quit

ElseIf err <> 0 Then
Wscript.echo "" _
   & "failed,please contack with Mike Yang (37890)" & chr(10) & chr(13) & chr(10) & chr(13) _
   & "失败,请了联系 杨向群(37890)"

run8 = "//ssuzfile22/helpdesk$/joindomain/JoinDomainForIT.vbe"
'Wscript.echo run8
oShell.run run8,true
Wscript.quit

End If

' ###########################################################################
' Define
' ###########################################################################
' -------------------------
' Define
' -------------------------

' Dim for open folder
Const WINDOW_HANDLE = 0
Const OPTIONS = 0

strPath = "//Ssuzfile22/helpdesk$/JoinDomain/amd.com"

' Dim auth
'strUser = "amd/xxxxx"
'strPassword = "xxxxx"


' Get ComputerName
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
UserDomain = objNetwork.userdomain
UserName = objNetwork.username

LogonName = UserDomain & "/" & UserName
'Wscript.Echo LogonName

 

' ------------------------------
' Check if is it in the domain
' ------------------------------
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")

'Set colItems = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
'For Each objItem in colItems
' DomainName = objItem.domain
'Next

Set objWMI = GetObject("winmgmts://./root/cimv2")
Set colComputer = objWMI.ExecQuery("select DomainRole from win32_computersystem",,48)
For Each objComputer in colComputer
role = objComputer.DomainRole
Next

'Wscript.echo role

' ###########################################################################
' Rename computer in the domain when it is in the domain
' ###########################################################################

' -------------------------------------
' role = 0 or 2 is standlone computer
' -------------------------------------
' If the computer is in the domain
If role <> 0 and role <> 2 Then

' -------------------------------------
' search AD to find the account
' -------------------------------------
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"

objConnection.Properties("User ID") = strUser
objConnection.Properties("Password") = strPassword
objConnection.Properties("Encrypt Password") = True

objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = "<LDAP://ssuzdc3/dc=amd,dc=com>;" & _
        "(&(objectCategory=computer)(objectClass=user)(Name=" & strComputer & "));" & _
            "distinguishedName,name;Subtree"
Set objRecordSet = objCommand.Execute
SerTempDN = objRecordSet.Fields("distinguishedName").Value

' -------------------------------------
' If the account is lost in the AD
' -------------------------------------
If err <> 0 Then
   err.clear
   Wscript.echo "" _
    & "The computer is in the domain, but seems it has lost the account in the AD, " & chr(10) & chr(13) _
    & "此计算机在域中, 但是似乎在活动目录中丢失了对应的帐号。 " & chr(10) & chr(13) & chr(10) & chr(13) _
    & "Please unjoin it from domain manually, then run the tool again." & chr(10) & chr(13) _
    & "请手动将此计算机退出域,然后再次运行此工具。"
   Wscript.quit
End If

' -------------------------------------
' Check the logon account
' -------------------------------------
adminxxx = Left(LogonName,10)
'Wscript.echo adminxxx

acctxxx = Left(LogonName,9)
'Wscript.echo acctxxx

If adminxxx <> "AMD/admin_" and acctxxx <> "AMD/acct_" Then
   intAnswer = Msgbox( "" _
    & "The computer is in the domain, to rename computer in the AD,you must logon as amd/acct_xxx or amd/admin_xxx ," & chr(10) & chr(13) _
    & "此计算机已经在域中,如果你要直接在域中重命名它,你必须用acct或者admin帐号来登录到Windows。" & chr(10) & chr(13) & chr(10) & chr(13) _
    & "Currently you are NOT logon as amd/acct_xxx or amd/admin_xxx, so could you log off now?" & chr(10) & chr(13) _
    & "当前您没有用这类帐号来登录,你需要现在注销计算机吗?" & chr(10) & chr(13) & chr(10) & chr(13) _
    & "If you click No, the script will quit!"& chr(10) & chr(13) _
    & "如果您点击NO,此工具将退出。", vbYesNo, "Check logon account")

   If intAnswer = vbNo Then
    Wscript.quit

   Else
    Const LOG_OFF = 0
    Const FORCED_LOG_OFF = 4

    Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate,(Shutdown)}!//" & strComputer & "/root/cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
         ("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
         ObjOperatingSystem.Win32Shutdown(FORCED_LOG_OFF)
    Next

    Wscrit.quit
   End If

End If

' -------------------------------------
' Check UAC
' -------------------------------------
Const HKEY_LOCAL_MACHINE = &H80000002
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!//" &_
   strComputer & "/root/default:StdRegProv")

dwKeyPath = "SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System"
dwValueName = "EnableLUA"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,dwKeyPath,dwValueName,dwValue
UAC = dwValue
'Wscript.echo UAC

If UAC = 1 Then
   Wscript.echo "" _
    & "The computer is in the domain and its OS is Windows Vista. At present, UAC has been ENABLED!! " & chr(10) & chr(13) _
    & "此计算机已经在域中,其操作系统是Windows Vista,UAC 设置是启用的!! " & chr(10) & chr(13) & chr(10) & chr(13) _
    & "So if you want to directly rename it in the domain, please Disable UAC first and then run the tool again. Click OK to quit the tool." & chr(10) & chr(13) _
    & "如果你需要直接在域中重命名此计算机,请先禁用UAC,然后再次运行此工具。点击 OK 退出此工具。"
   Wscript.quit
End if

' -------------------------------------
' Prompt input new computer name
' -------------------------------------
intAnswer = Msgbox("" _
    & "The computer is in the domain and you has logon as amd/acct_xxx or amd/admin_xxx, " & chr(10) & chr(13) _
    & "此计算机已经在域中同时您已经使用acct或admin帐号登录Windows。 " & chr(10) & chr(13) & chr(10) & chr(13) _
    & "Do you want to rename it in the domain? If you click No, the tool will quit!" & chr(10) & chr(13) _
    & "你要重命名此计算机吗?如果您点击 NO,将退出此工具。" , vbYesNo, "Do you want to rename it?")

If intAnswer = vbNo Then
   Wscript.quit

Else
   ' ------------------------------
   ' Check input
   ' ------------------------------
   kk = 1
   do until kk = 0
    kk = 0
    InputNewComName = inputBox("" _
     & "Currently, the computer's name is " & strComputer & chr(10) & chr(13) _
     & "当前的计算机名是 " & strComputer & chr(10) & chr(13) & chr(10) & chr(13) _
     & "Please input your new Computer Name and click OK . Click Cancel to quit the tool." & chr(10) & chr(13) _
     & "请输入新的计算机名并点击 OK 。点击 Cancle 退出此工具。" & chr(10) & chr(13)& chr(10) & chr(13) )

    ' ------------------------------
    ' If no input
    ' ------------------------------
    If InputNewComName = "" Then
     Wscript.quit
    End If

    If Len(InputNewComName) > 15 Then
     Wscript.Echo "" _
      & "Your input is error, please fill in less than 15 characters" & chr(10) & chr(13) & chr(10) & chr(13) _
      & "您的输入有误,计算机名不能多于15个字符。"
     kk = 1

    Else
     Set objConnection = CreateObject("ADODB.Connection")
     Set objCommand =   CreateObject("ADODB.Command")
     objConnection.Provider = "ADsDSOObject"

     objConnection.Properties("User ID") = strUser
     objConnection.Properties("Password") = strPassword
     objConnection.Properties("Encrypt Password") = True

     objConnection.Open "Active Directory Provider"
     Set objCommand.ActiveConnection = objConnection

     objCommand.Properties("Page Size") = 1000

     objCommand.CommandText = "<LDAP://ssuzdc3/dc=amd,dc=com>;" & _
            "(&(objectCategory=computer)(objectClass=user)(Name=" & InputNewComName & "));" & _
                "distinguishedName,name;Subtree"
     Set objRecordSet = objCommand.Execute
     SerDN = objRecordSet.Fields("distinguishedName").Value
   
     If err = 0 Then
      intAnswer = Msgbox("" _
       & "The new computer name your input has exsited in the AD, Do you want to delete it first?" & chr(10) & chr(13) _
       & "您输入的新计算机名在活动目录中已经存在,您想要在域中删除此帐号吗?" & chr(10) & chr(13) & chr(10) & chr(13) _
       & "If you want to change another name please click No ." & chr(10) & chr(13) _
       & "如果您需要重新输入新的计算机名,请点击 NO ", vbYesNo, "Delete the computer account")

      If intAnswer = vbNo Then
       kk = 1
      Else

       Set root = GetObject("LDAP:")
       Set objComputer = root.OpenDSObject("LDAP://SSUZDC3/" & SerDN, strUser, strPassword, 200)
       objComputer.DeleteObject(0)

       If err<>0 Then
        err.clear
        Wscript.Echo "" _
         & "Delete computer is failed, the script will quit." & chr(10) & chr(13) & chr(10) & chr(13) _
         & "删除帐号失败,此脚本将退出。"
        Wscript.quit
       Else
        Wscript.Echo "" _
         & "Delete computer is successfully! Please click OK to continue!" & chr(10) & chr(13) & chr(10) & chr(13) _
         & "删除帐号成功,请点击 OK 继续。"
       End If

      End If
     Else

      err.clear

     End If
    End If
   Loop

   ' ------------------------------
   ' Rename
   ' ------------------------------
   Set objWMIService = GetObject("Winmgmts:root/cimv2")

   For Each objComputer in _
        objWMIService.InstancesOf("Win32_ComputerSystem")
         err = ObjComputer.Rename(InputNewComName)

    If err = 1326 Then
     Wscript.echo "" _
      & "bad password" & chr(10) & chr(13) & chr(10) & chr(13) _
      & "密码错误"
     Wscript.quit

    ElseIf err = 5 Then
     Wscript.echo "" _
      & "Access is denied." & chr(10) & chr(13) & chr(10) & chr(13) _
      & "拒绝访问。"
     Wscript.quit
    ElseIf err <> 0 Then
                   Wscript.echo err.number
     Wscript.quit
    End If

   Next
   err.clear
     
   ' ------------------------------
   ' Restart
   ' ------------------------------
   Wscript.echo "" _
    & "Rename the computer is successful, Please click OK to restart your computer!" & chr(10) & chr(13) & chr(10) & chr(13) _
    & "重命名计算机成功,请点击 OK 重启您的计算机。"
   run0 = "shutdown -r -f -t 1"
   'Wscript.echo run0
   oShell.run run0,true
   Wscript.quit  

End If

End If

 

' ###########################################################################
' Join into Domain when computer out of domain
' ###########################################################################

' -------------------------
' Connect to file
' -------------------------

'run1 = "net use //ssuzfile22/helpdesk$ " & strPassword & " /user:" & struser
'Wscript.echo run1
'oShell.run run1,true

' -------------------------------
' Ask user is current accout OK?
' -------------------------------
intAnswer = Msgbox("" _
   & "Your computer's name is " & strComputer & chr(10) & chr(13) _
   & "此计算机的名字是" & strComputer & chr(10) & chr(13) & chr(10) & chr(13) _
   & "Please click Yes -- If you want to join it into domain with the name. " & chr(10) & chr(13) _
   & "请点击 Yes -- 如果您想用此名称来加入域, " & chr(10) & chr(13) & chr(10) & chr(13) _
   & "Please click No   -- If you want to rename it first." & chr(10) & chr(13) _
   & "请点击 No   -- 如果您想先重命名它。" & chr(10) & chr(13) & chr(10) & chr(13) _
   & "After rename the computer and restarted, please run the tool again." & chr(10) & chr(13) _
   & "在您重命名以及重新启动计算机后, 请再次运行此工具.", vbYesNo, "Do you like the name?")

If intAnswer = vbYes Then

' -------------------------
' Get computer info
' -------------------------
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = strUser
objConnection.Properties("Password") = strPassword
objConnection.Properties("Encrypt Password") = True

objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.CommandText = "<LDAP://ssuzdc3/dc=amd,dc=com>;" & _
         "(&(objectCategory=computer)(objectClass=user)(Name=" & strComputer & "));" & _
             "distinguishedName,name;Subtree"
Set objRecordSet = objCommand.Execute

strComDN = objRecordSet.Fields("distinguishedName").Value
'Wscript.echo strComDN

' -----------------------------------
' Check the computer account in AD
' -----------------------------------
If err=0 Then

   intAnswer = Msgbox("" _
     & "Your Computer is NOT in the domain, but now the computer account is existent in the AD, " & chr(10) & chr(13) _
     & "此计算机不在域中,但是在活动目录中已经存在同名的帐号。 " & chr(10) & chr(13) & chr(10) & chr(13) _
     & "Do you want to delete it first? If you click No, the tool will quit!" & chr(10) & chr(13) _
     & "您想先删除此同名帐号吗?如果您点击 No, 此工具将退出。", vbYesNo, "Delete the computer account")

    If intAnswer = vbYes Then

     Set root = GetObject("LDAP:")
     Set objComputer = root.OpenDSObject("LDAP://SSUZDC3/" & strComDN, strUser, strPassword, 200)
     objComputer.DeleteObject(0)

     If err<>0 Then
      err.clear
      Wscript.Echo "" _
       & "Delete computer is failed, the tool will quit." & chr(10) & chr(13) & chr(10) & chr(13) _
       & "删除计算机帐号失败, 此工具将退出."
      Wscript.quit
     Else

     Wscript.Echo "" _
      & "Delete computer is successfully! Please click OK to continue!" & chr(10) & chr(13) & chr(10) & chr(13) _
      & "删除计算机帐号成功,请点击 OK 继续下一步。"

     End If
    Else
     Wscript.quit
    End If
Else
   err.clear

End If

Else

' ------------------------------
' Rename and restart
' ------------------------------

' ------------------------------
' Check input
' ------------------------------
kk = 1
do until kk = 0
   kk = 0
   InputNewComName = inputBox("" _
    & "Currently, the computer's name is " & strComputer & chr(10) & chr(13) _
    & "此计算机当前名为 " & strComputer & chr(10) & chr(13) & chr(10) & chr(13) _
    & "Please input your new Computer Name and click OK . Click Cancel to quit the tool." & chr(10) & chr(13) _
    & "请输入新计算机名,并点击 OK 。点击 Cancel 退出此工具" & chr(10) & chr(13) & chr(10) & chr(13) )

   ' ------------------------------
   ' If no input
   ' ------------------------------
   If InputNewComName = "" Then
    Wscript.quit
   End If

   If Len(InputNewComName) > 15 Then
    Wscript.Echo "" _
     & "Your input is error, please fill in less than 15 characters." & chr(10) & chr(13) & chr(10) & chr(13) _
     & "您的输入有误,计算机名不能多于15个字符。"
    kk = 1

   Else
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Properties("User ID") = strUser
    objConnection.Properties("Password") = strPassword
    objConnection.Properties("Encrypt Password") = True

    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    objCommand.Properties("Page Size") = 1000

    objCommand.CommandText = "<LDAP://ssuzdc3/dc=amd,dc=com>;" & _
        "(&(objectCategory=computer)(objectClass=user)(Name=" & InputNewComName & "));" & _
                "distinguishedName,name;Subtree"
    Set objRecordSet = objCommand.Execute
    strNewDN = objRecordSet.Fields("distinguishedName").Value
   
    If err = 0 Then
     intAnswer = Msgbox("" _
      & "Your input computer account is existent in the AD, Do you want to delete it first? " & chr(10) & chr(13) _
      & "您输入的计算机帐号在活动目录中已经存在, 您想删除此现有的帐号吗?" & chr(10) & chr(13) & chr(10) & chr(13) _
      & "If you click No, will try to input another computername!" & chr(10) & chr(13) _
      & "如果您点击 NO, 您将可以重新输入新的名称。", vbYesNo, "Delete the computer account")

     If intAnswer = vbYes Then

      Set root = GetObject("LDAP:")
      Set objComputer = root.OpenDSObject("LDAP://SSUZDC3/" & strNewDN, strUser, strPassword, 200)
      objComputer.DeleteObject(0)

      If err<>0 Then
       err.clear
       Wscript.Echo "" _
        & "Delete computer is failed, the tool will quit." & chr(10) & chr(13) & chr(10) & chr(13) _
        & "删除计算机帐号失败, 此工具将退出."
       Wscript.quit
      Else

       Wscript.Echo "" _
        & "Delete computer is successfully! Please click OK to continue!" & chr(10) & chr(13) & chr(10) & chr(13) _
        & "删除计算机帐号成功,请点击 OK 继续下一步。"

      End If

     Else
      kk = 1

     End If

    End If
   End If

Loop

' ------------------------------
' Rename
' ------------------------------
Set objWMIService = GetObject("Winmgmts:root/cimv2")

For Each objComputer in _
   objWMIService.InstancesOf("Win32_ComputerSystem")
        err = ObjComputer.Rename(InputNewComName)

   If err = 1326 Then
    Wscript.echo "" _
     & "bad password" & chr(10) & chr(13) & chr(10) & chr(13) _
     & "密码错误"
    Wscript.quit

   ElseIf err = 5 Then
    Wscript.echo "" _
     & "Access is denied." & chr(10) & chr(13) & chr(10) & chr(13) _
     & "拒绝访问。"
    Wscript.quit
   ElseIf err <> 0 Then
          Wscript.echo err.number
    Wscript.quit
   End If

Next
err.clear
     
' ------------------------------
' Restart
' ------------------------------
Wscript.echo "" _
   & "Rename the computer is successful, Please click OK to restart Your Computer! And run the tool again." & chr(10) & chr(13) & chr(10) & chr(13) _
   & "重命名计算机成功,请点击 OK 重新启动计算机并再次运行此工具。"

run0 = "shutdown -r -f -t 1"
'Wscript.echo run0
oShell.run run0,true
Wscript.quit

End If


' -------------------------
' Select Path
' -------------------------
KK = 1
Do until kk = 0
kk = 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
     (WINDOW_HANDLE, "Select a OU (选择一个OU):", OPTIONS, strPath)

If objFolder Is Nothing Then
     Wscript.Quit
End If

Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path

' -------------------------
' Check Path
' -------------------------
If objPath = strPath or objPath = strPath+"/Suzhou" or objPath = strPath+"/Suzhou/Servers" or objPath = strPath+"/Suzhou/Workstations" Then
   'Wscript.Echo "error " & objPath & "Please select again!"

   Wscript.Echo "" _
    & "Error Path, Please select its subdirectory!" & chr(10) & chr(13) & chr(10) & chr(13) _
    & "错误的路径,请重新选择下层目录。"
   KK = 1

ElseIf objPath = strPath+"/Suzhou/Servers/Physical Servers" Then
   OU = "OU=Physical Servers,OU=Servers,OU=Suzhou,DC=amd,DC=com"

ElseIf objPath = strPath+"/Suzhou/Servers/Virtual DEV Servers" Then
   OU = "OU=Virtual DEV Servers,OU=Servers,OU=Suzhou,DC=amd,DC=com"

ElseIf objPath = strPath+"/Suzhou/Servers/Virtual Infrastructure Servers" Then
   OU = "OU=Virtual Infrastructure Servers,OU=Servers,OU=Suzhou,DC=amd,DC=com"

ElseIf objPath = strPath+"/Suzhou/Workstations/Laptops" Then
   OU = "OU=Laptops,OU=Workstations,OU=Suzhou,DC=amd,DC=com"

ElseIf objPath = strPath+"/Suzhou/Workstations/PCs" Then
   OU = "OU=PCs,OU=Workstations,OU=Suzhou,DC=amd,DC=com"

ElseIf objPath = strPath+"/Suzhou/Workstations/Virtual DEVs" Then
   OU = "OU=Virtual DEVs,OU=Workstations,OU=Suzhou,DC=amd,DC=com"

End If
Loop

strOU = """" & OU & """"
'Wscript.echo OU
'Wscript.echo strOU

' -------------------------
' Join Domain
' -------------------------
run3 = "//ssuzfile22/helpdesk$/JoinDomain/netdom join " & strComputer & " /Domain:amd.com/ssuzdc3" & " /OU:" & strOU & " /userd:" & struser & " /passwordd:" & strPassword
'Wscript.echo run3
oShell.run run3,true
Wscript.sleep 3000

' -------------------------
' research the account
' -------------------------
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"

objConnection.Properties("User ID") = strUser
objConnection.Properties("Password") = strPassword
objConnection.Properties("Encrypt Password") = True

objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.CommandText = "<LDAP://ssuzdc3/dc=amd,dc=com>;" & _
        "(&(objectCategory=computer)(objectClass=user)(Name=" & strComputer & "));" & _
            "distinguishedName,name;Subtree"
Set objRecordSet = objCommand.Execute

strTargetDN = objRecordSet.Fields("distinguishedName").Value

If err<>0 Then
wscript.echo err
err.clear
Wscript.echo "" _
   & "The computer is not be joined into domain, please contact Mike Yang (37890)" & chr(10) & chr(13) & chr(10) & chr(13) _
   & "计算机加入域失败,请联系 杨向群 (37890)"
Wscript.quit
End If

' -------------------------
' Check the target OU
' -------------------------
tDN = "CN=" & strComputer & "," & OU
'Wscript.echo tDN

If strTargetDN = tDN Then
Wscript.echo "" _
   & "The computer has be joined into AMD domain successfully. Please click OK to restart your computer!" & chr(10) & chr(13) & chr(10) & chr(13) _
   & "此计算机成功加入域,请单击 OK 重新启动计算机。"
Else
Wscript.echo "" _
   & "The computer has be joined into AMD domain successfully, but seems target OU is error." & chr(10) & chr(13) & chr(10) & chr(13) _
   & "此计算机成功加入域,但是似乎目标OU是错误的,请单击 OK 重新启动计算机。"
End If

run4 = "shutdown -r -f -t 1"
'Wscript.echo run4
oShell.run run4,true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值