Clicky

I have that attached htm script that should allow our engineers to choose what Trust, whether it is a laptop or workstation followed by their user name and password.

Once the engineer is authenticated, they should be able to join the XP SP3 machines to our new domain.

But this script does not do that.
Does anyone know what is missing or incorrect in this script?

 <html>  <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>My HTML Application</title> <script language="vbscript">  Sub SubmitButton_onClick()       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 strDepartmentValue 	  Dim strErrorTxt 	         strDomain = "AAA"     	StrAccountOU = "OU="&window.Type.value&",OU=Computers,OU="&window.Trust.value&",OU=Customers,DC="&strDomain&",DC=local" 	MsgBox  "Output :" & strAccountOU & ":"        strPassword = window.AdmPwd.value       strUser = window.AdmUsername.value               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, StrAccountOU, _              JOIN_DOMAIN + ACCT_CREATE)              ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _           strPassword, strUser, StrAccountOU, _               JOIN_DOMAIN + ACCT_CREATE)              Set objNetwork = Nothing              End Sub  </script>  </head> <body> <p>   <table cellspacing="0" cellpadding="5" border="0" width="500px">  <tr> <td><strong>Select Trust</strong>:</td> <td><select id="Trust" name="Trust"">       <option value="">[Select Trust]</option>       <option value="A PCT">A PCT</option>       <option value="B PCT">B PCT</option>       <option value="C PCT">C PCT</option> </select></td> </tr>  <tr> <td><strong>Select Type</strong>:</td> <td><select id=2 name="Type">       <option value="Workstations">Workstations</option>       <option value="Portable Laptops">Portable Laptops</option> </select></td> </tr>  <tr> <td><strong>Admin Username</strong>:</td> <td><input type="text" size="30" name="AdmUsername" id="AdmUsername"></td> </tr>  <tr> <td><strong>Admin Password</strong>:</td> <td><input type="password" size="30" name="AdmPwd" id="AdmPwd"></td> </tr>   </table>  <input type="button" id="SubmitButton" name="SubmitButton" value="Submit">  </body> </html>                             
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 

Select allOpen in new window

asked 11/29/2011 09:36

tedcbe's gravatar image

tedcbe ♦♦


8 Answers:
Hello !

This part is wrong, the part in bold should be removed :

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

Also, is the user a domain user or a local user ? A local user can't join the workstation to the domain (I believe you know but I had to make sure).

You should try without specifying the OU first.
link

answered

SylvainDrapeau's gravatar image

SylvainDrapeau

As soon as I click on Submit it shows

Output :OU=Workstations,OU=Computers,OU=ABC,OU=Customers,DC=Central,DC=local:

when I click on OK nothing happens

When I click on the exclamation mark on the status bar it says "Active X component cant create object: 'GetObject'

link

answered 2011-11-30 at 06:33:31

tedcbe's gravatar image

tedcbe

Hi SylvainDrapeau,

Thank you for your response.
I have removed the section you asked me to remove and it still does not do anything.
I am entering my admin credentials but that hasnt worked.
Mind it I am testing this script on my machine which has already been joined to the domain.
Will this make a difference?

Ted
link

answered 2011-11-30 at 06:37:41

tedcbe's gravatar image

tedcbe

Hello !

Got it I think... WMI is not safe for scripting and IE's security level prevents it from working.

Changing your file extention from HTML to HTA makes it a Hypertext Application which should allow your code to run locally.

Found in this article
link

answered 2011-11-30 at 06:51:22

SylvainDrapeau's gravatar image

SylvainDrapeau

We've tried naming it .htm but that hasnt worked as well.
Hence we have settled for the attached vbscript. I've tested it and it works fine.
however the boxes that come up like 'Trust' and 'Machine type' will require the engineers to enter this information manually thus making it prone to errors.

Is there a way of entering this information in the script so that it appears as a drop down and users can choose from one of those?

Also is it possible to mask the password as it now being entered in plain text?

I am trying to get some bits and bobs in so that it looks more graceful like having a confirmation box say whether the join to the domain was successfull or not and to prompt them to enter the correct credentials.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Option Explicit

Dim strDomain, strUser, strPassword
Dim objNetwork, strComputer, objComputer, lngReturnValue
Dim strOU

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 strTrust
Dim strType



'strTrust=InputBox("Trust","Trust","")
'strType=InputBox("Machine Type","Machine Type","")
'strUser=InputBox("Username","Username","")
'strPassword=InputBox("Password","Password","")
strDomain = "Central.local"

strOU = "ou=" & strType &";ou=Computers;ou=" & strTrust & ";ou=Customers;dc=Centra;dc=local"

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

Set objComputer = GetObject("winmgmts:" _
& "{impersonationLevel=Impersonate,authenticationLevel=Pkt}!\" & _
strComputer & "
ootcimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")

lngReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, strDomain & "" & strUser, strOU, _
JOIN_DOMAIN + ACCT_CREATE)

Wscript.Echo "strComputer = " & strComputer
Wscript.Echo "strDomain = " & strDomain
Wscript.Echo "strUser = " & strUser
Wscript.Echo "Target OU = " & strOU

Wscript.Echo "ReturnValue = " & CStr(lngReturnValue)
link

answered 2011-11-30 at 09:06:40

tedcbe's gravatar image

tedcbe

Hi !

look here for how to populate a drop down list from a text file.
link

answered 2011-11-30 at 10:07:43

SylvainDrapeau's gravatar image

SylvainDrapeau

Sorry about the delay in getting back to you. The script that I had attached earlier worked on few machines but did not work on 2 more.
Hence we have decided to  use the batch file that uses netdom to join the machines to the domain.
I've attached the portion of the script that we are using.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
:: Organisation OU Commands

:organisation name
echo Joining %computername% to the CENTRAL domain
echo Laptop will be placed into the following OU
echo.
echo "CENTRAL.LOCAL/Computers/Workstations"
echo.
echo Type your domainusername ie centraljbloggs and press enter.
SET /P variable=
"c:join2domain	ools
etdom" join %computername% /domain:central.local /OU:"ou=workstations,ou=Computers,OU=org name,OU=org name,DC=Central,DC=Local" /userD:%variable% /passwordD:* /reb:1
goto end
link

answered 2011-11-30 at 17:31:25

tedcbe's gravatar image

tedcbe

thanks for your help sylvainDrapeau.

link

answered 2011-12-01 at 10:04:53

tedcbe's gravatar image

tedcbe

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1

Asked: 11/29/2011 09:36

Seen: 293 times

Last updated: 12/09/2011 05:18