[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Join PC to Domain vbs

Posted on 2014-08-18
1
Medium Priority
?
95 Views
Last Modified: 2015-01-16
Hi, I want to modify the script below to provide an inputbox for username, password domain. The inputbox values will then become strdomain, struser, strpassword. This will allow me to join a PC to the domain via script. thanks in advance.

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

If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
      ' Duff arguments so return non zero so the task is marked as failed.
      WScript.Quit(1)
Else

      strDomain   = WScript.Arguments.Item(0)
      strUser = WScript.Arguments.Item(1)
      strPassword = WScript.Arguments.Item(2)

      'set DNS IP address
      If WScript.Arguments.Count = 4 Then
                strDNSIP = WScript.Arguments.Item(3)
                Set objShell = CreateObject("WScript.shell")
                objShell.Run "netsh int ip set dns ""local area connection"" static " & _
                            strDNSIP &" primary", 0 , 0
       End If
End If

strMessage =Inputbox("Enter your Username","Input Required")
WScript.Echo strMessage

Inputbox=strUser

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName


Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
                             strComputer & _
                             "\root\cimv2:Win32_ComputerSystem.Name='" _
                             & strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
                                                strPassword, _
                                                strDomain & "\" & strUser, _
                                                NULL, _
                                                JOIN_DOMAIN+ACCT_CREATE)

WScript.Quit(ReturnValue)
0
Comment
Question by:kwatt562
1 Comment
 
LVL 37

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 40267629
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   = Inputbox("Enter your domain","Input Required")
       strUser = Inputbox("Enter your Username","Input Required")
       strPassword = Inputbox("Enter your Password","Input Required")

 Set objNetwork = CreateObject("WScript.Network")
 strComputer = objNetwork.ComputerName


 Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
                              strComputer & _
                              "\root\cimv2:Win32_ComputerSystem.Name='" _
                              & strComputer & "'")

 ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
                                                 strPassword, _
                                                 strDomain & "\" & strUser, _
                                                 NULL, _
                                                 JOIN_DOMAIN+ACCT_CREATE)

 WScript.Quit(ReturnValue)

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question