Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. ' JoinDomain.vbs
  2. ' VBScript program to join a computer to a domain.
  3. ' The computer account is created in Active Directory.
  4. ' The computer must have XP or above.
  5. ' The AD must be W2k3 or above.
  6. ' See c:\Windows\debug\NetSetup.log for details.
  7.  
  8. Option Explicit
  9.  
  10. Dim strDomain, strUser, strPassword, strOU
  11. Dim objNetwork, strComputer, objComputer, lngReturnValue
  12.  
  13. Const JOIN_DOMAIN = 1
  14. Const ACCT_CREATE = 2
  15. Const ACCT_DELETE = 4
  16. Const WIN9X_UPGRADE = 16
  17. Const DOMAIN_JOIN_IF_JOINED = 32
  18. Const JOIN_UNSECURE = 64
  19. Const MACHINE_PASSWORD_PASSED = 128
  20. Const DEFERRED_SPN_SET = 256
  21. Const INSTALL_INVOCATION = 262144
  22.  
  23. ' Prompt for credentials.
  24. strDomain = InputBox("Enter name of domain")
  25. strUser = InputBox("Enter account name to use")
  26. strPassword = InputBox("Enter the account password")
  27.  
  28. ' Specify the OU where the computer object will be created.
  29. strOU = "ou=Computers,ou=West,dc=mydomain,dc=com"
  30.  
  31. ' Retrieve NetBIOS name of local computer.
  32. Set objNetwork = CreateObject("WScript.Network")
  33. strComputer = objNetwork.ComputerName
  34.  
  35. Set objComputer = GetObject("winmgmts:" _
  36. & "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!\\" & _
  37. strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
  38. strComputer & "'")
  39.  
  40. lngReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
  41. strPassword, strDomain & "\" & strUser, strOU, _
  42. JOIN_DOMAIN + ACCT_CREATE)
  43.  
  44. Wscript.Echo "ReturnValue = " & CStr(lngReturnValue)
  45.  
  46. Select Case lngReturnValue
  47. ' Some return code values (added 04/05/2010).
  48. Case 0
  49. Wscript.Echo "Success joining computer to the domain!"
  50. Case 5
  51. Wscript.Echo "Access is denied"
  52. Case 87
  53. Wscript.Echo "The parameter is incorrect"
  54. Case 110
  55. Wscript.Echo "The system cannot open the specified object"
  56. Case 1323
  57. Wscript.Echo "Unable to update the password"
  58. Case 1326
  59. Wscript.Echo "Logon failure: unknown username or bad password"
  60. Case 1355
  61. Wscript.Echo "The specified domain either does not exist or could not be contacted"
  62. Case 2224
  63. Wscript.Echo "The account already exists"
  64. Case 2691
  65. Wscript.Echo "The machine is already joined to the domain"
  66. Case 2692
  67. Wscript.Echo "The machine is not currently joined to a domain"
  68. Case Else
  69. Wscript.Echo "Unknown error"
  70. End Select
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement