No announcement yet.

Drop down menu/list

  • Filter
  • Time
  • Show
Clear All
new posts

  • Drop down menu/list

    I have created a HTA application from combing scripts from about 6 different sources..

    I am looking for an example of how to create a drop down menu/list from a specific OU or container in AD.

    I have setup AD for our users with three parts, a Department OU, a Job Title OU, and the users Container.

    I would like to have a drop down where I can select a Department(group), then another drop down to select Job Title(group). (there are many users that have the same job titles)

    My existing script inserts the Department and Job Title from the HTA form via a text box insert into the AD schema perfectly. I would like to take this one step further and use the afformentioned drop down men/list to add users to specific department group & a job title group while also still filling in the fields in the AD schema..

    here is my current script/HTA form


    APPLICATIONNAME="Account Creation" 
    <title>User Account Creation Form</title> 
    <style type="text/css"> 
    .style3 {font-size: 13px} 
    body,td,th { 
    font-family: Arial, Helvetica, sans-serif; 
    .style2 { font-family: Arial, Helvetica, sans-serif; 
    font-size: 13.5pt; 
    color: #CC6600; 
    font-weight: bold; 
    .style5 {font-size: small; color: #FF0000; } 
    .style6 {color: #FF0000} 
    <script type="text/vbscript"> 
    Sub CreateAccount 
    strUser = TextBox0.Value 
    If strUser = "" Then 
    MsgBox "You're missing required fields.",64, "Alert" 
    Exit Sub 
    End If
    strFirst = TextBox1.Value 
    If strFirst = "" Then 
    MsgBox "You're missing required fields",64, "Alert" 
    Exit Sub 
    End If 
    strLast = TextBox2.Value 
    If strLast = "" Then 
    MsgBox "You're missing required fields",64, "Alert" 
    Exit Sub 
    End If 
    strDepartment = TextBox3.Value 
    If strDepartment = "" Then 
    MsgBox "You're missing required fields",64, "Alert" 
    Exit Sub 
    End If
    strTitle = TextBox4.Value 
    If strTitle = "" Then 
    MsgBox "You're missing required fields",64, "Alert" 
    Exit Sub 
    End If  
    strDisplay = strLast & ", " & strFirst 
    Set objConnection = CreateObject("ADODB.Connection") 
    objConnection.Open "Provider=ADsDSOObject;" 
    Set objCommand = CreateObject("ADODB.Command") 
    objCommand.ActiveConnection = objConnection 
    objCommand.CommandText = _ 
    "<GC://dc=nlc,dc=com>;(&(objectCategory=Person)(objectClass=user)" & _ 
    "(samAccountName=" & strUser & "));samAccountName;subtree" 
    Set objRecordSet = objCommand.Execute 
    If objRecordSet.RecordCount = 0 Then 
    MsgBox "The User Account already exists.",48,"Alert" 
    Exit Sub 
    End If 
    strDisplay = strFirst & " " & strLast 
    strCN = strFirst & " " & strLast
    Set objOU = GetObject("LDAP://CN=Users,DC=nlc,DC=com") 
    Set objUser = objOU.Create("User", "cn=" & strCN)
    objUser.Put "sAMAccountName", LCase(strUser)
    objUser.Put "userPrincipalName", LCase(strUser & "")
    objUser.Put "mail", LCase(strUser & "")
    objUser.Put "givenName", strFirst 
    objUser.Put "sn", strLast 
    objUser.Put "displayName", strDisplay
    objUser.Put "department", strDepartment
    objUser.Put "title", strTitle
    objUser.SetPassword "password" 
    objUser.Put "pwdLastSet", 0 
    intUAC = objUser.Get("userAccountControl") 
    objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE 
    End If 
    'This Section will Create The Users Home Drive on \\SERVERNLC\Users\ 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFolder = objFSO.CreateFolder("\\SERVERNLC\Users\" & strUser) 
    'This Section will give the user change NTFS permissions to their home drives. 
    Set objShell = CreateObject("Wscript.Shell") 
    strDest = "\\SERVERNLC\Users\" & strUser 
    objShell.Run ("SetACL.exe -on """ & strDest & """ -ot file -actn ace " & "-ace ""\" & strUser & ";p:full""")
    End Sub 
    Sub Reload 
    End Sub 
    Sub bodyLoaded() 
    End Sub 
    <body onLoad="bodyLoaded()">
    <p><img src="logo.jpg"></p> 
    <p class="style2">Network Account Creation</p> 
    <table width="289" border="0" align="left"> 
    <td width="89"><span class="style5">*</span>Login ID: </td> 
    <td width="144"><input type="text" name="textbox0"></td> 
    <td><span class="style5">*</span>First Name:</td> 
    <td><input type="text" name="textbox1"></td> 
    <td><span class="style5">*</span>Last Name: </td> 
    <td><input type="text" name="textbox2"></td> 
    <td><span class="style5">*</span>Department:</td> 
    <td><input type="text" name="textbox3"></td> 
    <td><span class="style5">*</span>Job Title:</td> 
    <td><input type="text" name="textbox4"></td> 
    <input type="button" name="Submit" value="Submit" onClick="CreateAccount"> 
    <p>The login ID will have an initial password of password. </p> 
    <p>The new employee will also be required to change their password at first logon. </p> 
    <p class="style3"><span class="style6">*</span> Indicates Required Field</p> 
    <input id="reloadbutton" class="button" type="reset" value="Clear Form" name="reload_button" onClick="Reload"> 
    <input type="button" value=" Exit " name="close_button" onClick="Self.Close"> 

  • #2
    Re: Drop down menu/list

    In HTA you can create a static list containing values for showing in a dropdownlist.

    But if you want to use an 'array' as a list, you have to use a special ComboBox Control.
    This combobox comes with MS-Office, so you can run this HTA only from a computer where Office is installed.

    The combobox object in the HTMLbody is linked by an "id=ComboBox1" to a list in the script part.
    That list will be an array: ComboBox1.List = arrUsers
    Following the link above in the 'ms script center' article, you see in the last script example, how to populate the array using a (For-Next) loop <-- In your case that must be For each objUser in objOU.

    You can create two drop down menus.
    The first one will be with a static list that is containing the names of the OUs or Containers
    (first option: ------- Choose an AD container/OU ------- ) OnChange start the right query.
    The second drop down list will then showing the results of the query, where you can select one option and click an OK-button to proceed.



    An example
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDomainDN = objRootDSE.Get("DefaultNamingContext")
    Sub GetObject
      strOU = OptionChooser.Value  '<--RDN of the container/ou , returned from the 1st drop down menu
      strOU = strOu & "," & strDomainDN
      Dim arrNames() : intSize = 0
      Set objOU = GetObject("LDAP://" & strOU)
      objOU.Filter = Array("user")
      For Each User in objOU
         ReDim Preserve arrNames(intSize)
         arrNames(intSize) = User.CN
         intSize = intSize + 1
      'quick_Sort by name:
      For i = (UBound(arrNames) - 1) to 0 Step -1
          For j= 0 to i
              If UCase(arrNames(j)) > UCase(arrNames(j+1)) Then
                  strHolder = arrNames(j+1)
                  arrNames(j+1) = arrNames(j)
                  arrNames(j) = strHolder
              End If
      ComboBox1.List = arrNames '<------ Dynamic list for the 2nd Drop Down List
    End Sub
    1st Drop down list containing the OUs (value is RDN):
    <select size="1" name="OptionChooser" onChange="GetObject">
        <option value="">--- Choose an AD container/OU ---</option>
        <option value="OU=Department">Department</option>
        <option value="OU=Job Title">Job Title</option>
        <option value="CN=users">users</option>
    Last edited by Rems; 22nd October 2007, 23:14. Reason: typos

    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts