Join PC to Domain vbs

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)
kwatt562Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.