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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 554
  • Last Modified:

Rejoinder code need some additions.

Hi,

Rejoinder code need some additions.

1. You gave me a code that can add users to Distribution and security groups. Can that code be added to the below. Code. So i can do both in one.
2. A way to get all computers in the domain. To be shown. In a box. Search the whole Domain (Local only)
3. To show all Users in an OU in a box. I have all users in my Domain in one box so i can see all of them in the Box. (Local Only)
4. To show all contacts in an OU in a box. (Local only)
All the above to have the total count and member of how many groups count shown.

I know all this will take a very long time to process. See if this can be saved after the first query some where in the local HDD and check slowly in the background after opening the app later.

So once opened it gets the data fast and starts processing in the background. And let me start quering any other data.

5. When the users are shown it has to show me how many groups it's a member of evern quering the root Domain.

6. Any way to have an option to reset the local password of the machine i want i am quering.

Regards
Sharath
<head>
<title>User Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="User Information"
     BORDER="thin"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="MAXIMIZE"
     ID="oHTA"
>
<APPLICATION:HTA>
</head>
 
<script language="VBScript">
Const adVarChar = 200
Const VarCharMaxCharacters = 255
Const adFldIsNullable = 32
 
'http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q__23804616.html
 
Dim strEmailBCC
Dim strEmailServer
Dim arrSubjectText
Dim arrDomainNames
 
strEmailBCC         = "" 'Enter the BCC field as "Your Name <youremail@yourdomain.com>"
strEmailServer      = "MAILSERVER" 'Exchange server name
arrSubjectText      = array("This is subject text #1","This is subject text #2","This is subject text #3","This is subject text #4","This is subject text #5","This is subject text #6","This is subject text #7","This is subject text #8")
arrToSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
arrCCSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
strEmailFrom        = "" 'Leave Blank if the HTA should determine email address automatically
 
'Uncomment the next line to input your own domain names
'arrDomainNames      = array("DOMAIN","DC=subdomain1,DC=domain,DC=com")
 
boolAllowPing       = False 'Set to true to allow the interface to ping computers.
boolLookupLastLogin = False 'Set to true to allow the interface to query last logons
boolTableReports    = False 'Set to true to allow the interface to use table format reports
 
Dim arrRows
Dim strEmailFrom
Dim strEmailTo
Dim strEmailCC
Dim DataList
Dim globalstrSearchField
Dim globalstrSearchBtnPush
Dim FileName
Dim fModif
Dim LastChildMenu
Dim LastMenu
Dim globalstrQueryBuilder
 
if NOT IsArray(arrDomainNames) then
    GetDomainNames
End If
 
If strEmailFrom = "" Then
    strEmailFrom = mid(GetEmailAddresses(GetUsersEmailAddress),1,len(GetEmailAddresses(GetUsersEmailAddress))-1)
    strEmailFrom = GetUsersEmailAddress & " <" & strEmailFrom & ">"	'Getting email address from logged on user
End if
 
strEmailTo = GetUsersEmailAddress	'Get user name of logged on user so there is a default value when launched
strEmailCC = ""
 
DisplayTitle
Set LastChildMenu = Nothing
Set LastMenu = Nothing
 
Set oShell = CreateObject("WScript.Shell")
fTemp      = oShell.ExpandEnvironmentStrings("%TEMP%")
fAppData   = oShell.ExpandEnvironmentStrings("%APPDATA%")
 
Set MailboxList = CreateObject("ADOR.Recordset")
MailboxList.Fields.Append "legacyExchangeDN", adVarChar, VarCharMaxCharacters
MailboxList.Fields.Append "mailboxsize", adVarChar, VarCharMaxCharacters
MailboxList.Open
 
Set GroupMembershipDB = CreateObject("ADOR.Recordset")
GroupMembershipDB.Fields.Append "SAMAccountName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "PrimaryGroupToken", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "SAMAccountType", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "MemberDistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Open
 
set dicGroupNumbers = CreateObject("Scripting.Dictionary")
 
Sub GetDomainNames
    set objRootDSE   = GetObject("LDAP://RootDSE")
    strBase          = "<LDAP://cn=Partitions," & objRootDSE.Get("ConfigurationNamingContext") & ">;"
    strFilter        = "(&(objectcategory=crossRef)(systemFlags=3));"
    strAttrs         = "name,trustParent,nCName,dnsRoot,distinguishedName;"
    strScope         = "onelevel"
    set objConn      = CreateObject("ADODB.Connection")
    objConn.Provider = "ADsDSOObject"
    objConn.Open "Active Directory Provider"
    set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
    objRS.MoveFirst
    
    set arrDomainNames     = CreateObject("Scripting.Dictionary")
    set dicDomainHierarchy = CreateObject("Scripting.Dictionary")
    set dicDomainRoot      = CreateObject("Scripting.Dictionary")
    
    while not objRS.EOF 
        dicDomainRoot.Add objRS.Fields("name").Value, objRS.Fields("nCName").Value
        if objRS.Fields("trustParent").Value <> "" then
            arrDomainNames.Add objRS.Fields("name").Value, 0
            set objDomainParent = GetObject("LDAP://" & objRS.Fields("trustParent").Value)
            dicDomainHierarchy.Add objRS.Fields("name").Value,objDomainParent.Get("name")
       else 
            arrDomainNames.Add objRS.Fields("name").Value, 1
       end if
       objRS.MoveNext
    wend
    for each strDomain in arrDomainNames
        'msgbox strDomain
    next
End Sub
 
Sub Window_OnLoad
      'Uncomment the following lines to hide them from the GUI
      'tr_seatno.classname="HideFromGUI"
      'tr_replacementseatno.classname="HideFromGUI"
      'tr_building.classname="HideFromGUI"
      'tr_extensionno.classname="HideFromGUI"
      'tr_empid.classname="HideFromGUI"
      'tr_department.classname="HideFromGUI"
      'tr_designation.classname="HideFromGUI"
      'tr_name.classname="HideFromGUI"
      'tr_loginname.classname="HideFromGUI"
      'tr_email.classname="HideFromGUI"
      'tr_mailboxsize.classname="HideFromGUI"
      'tr_mailboxstore.classname="HideFromGUI"
      'tr_mobileno.classname="HideFromGUI"
      'tr_company.classname="HideFromGUI"
      'tr_address.classname="HideFromGUI"
      'tr_city.classname="HideFromGUI"
      'tr_state.classname="HideFromGUI"
      'tr_zipcode.classname="HideFromGUI"
      'tr_country.classname="HideFromGUI"
      'tr_homephone.classname="HideFromGUI"
      'tr_manager.classname="HideFromGUI"
      'tr_whencreated.classname="HideFromGUI"
      'tr_oupathuser.classname="HideFromGUI"
      'tr_lastlogintimestamp.classname="HideFromGui"
      'tr_notes.classname="HideFromGUI"
      'tr_computerserialno.classname="HideFromGUI"
      'tr_replacedmachine.classname="HideFromGUI"
      'tr_replacedcomputerserialno.classname="HideFromGUI"
      'tr_oupathcomputer.classname="HideFromGUI"
      'tr_computeros.classname="HideFromGUI"
      'tr_computerdescription.classname="HideFromGUI"
      'tr_computercreated.classname="HideFromGUI"
      'tr_groupmembership.classname="HideFromGUI"
      'tr_dgmembership.classname="HideFromGUI"
      'tr_managerlist.classname="HideFromGUI"
      'tr_subordinates.classname="HideFromGUI"
      
      TestToSeeWhatLinesAreHidden
      
      btnFirstEvent.Disabled = True
      btnPreviousEvent.Disabled = True
      btnNextEvent.Disabled = True
      btnLastEvent.Disabled = True
      btnEmailThisRecord.Disabled = True
      btnEMailAllRecords.Disabled = True
      btnEmailAsAttachment.Disabled = True
      txt_EmailTo.Value = strEmailTo
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      FillGroupList
      FillManagerList
      FillSubjectList
      GetChkProfiles
      GetMailboxDetails
      chk_TableReports.Checked = boolTableReports
      chk_LookupLastLogin.Checked = boolLookupLastLogin
      chk_AllowPings.Checked = boolAllowPing
      txt_EmailSubject_OnChange
End Sub
 
Sub TestToSeeWhatLinesAreHidden
      'Test to see what lines are hidden and uncheck the boxes
      if tr_seatno.classname="HideFromGUI" then chk_seatno.Checked = False
      if tr_replacementseatno.classname="HideFromGUI" then chk_replacementseatno.Checked = False
      if tr_building.classname="HideFromGUI" then chk_building.Checked = False
      if tr_extensionno.classname="HideFromGUI" then chk_extensionno.Checked = False
      if tr_empid.classname="HideFromGUI" then chk_empid.Checked = False
      if tr_department.classname="HideFromGUI" then chk_department.Checked = False
      if tr_designation.classname="HideFromGUI" then chk_designation.Checked = False
      if tr_name.classname="HideFromGUI" then chk_name.Checked = False
      if tr_loginname.classname="HideFromGUI" then chk_loginname.Checked = False
      if tr_email.classname="HideFromGUI" then chk_email.Checked = False
      if tr_mailboxsize.classname="HideFromGUI" then chk_mailboxsize.Checked = False
      if tr_mailboxstore.classname="HideFromGUI" then chk_mailboxstore.Checked = False
      if tr_mobileno.classname="HideFromGUI" then chk_mobileno.Checked = False
      if tr_company.classname="HideFromGUI" then chk_company.Checked = False
      if tr_address.classname="HideFromGUI" then chk_address.Checked = False
      if tr_city.classname="HideFromGUI" then chk_city.Checked = False
      if tr_state.classname="HideFromGUI" then chk_state.Checked = False
      if tr_zipcode.classname="HideFromGUI" then chk_zipcode.Checked = False
      if tr_country.classname="HideFromGUI" then chk_country.Checked = False
      if tr_homephone.classname="HideFromGUI" then chk_homephone.Checked = False
      if tr_manager.classname="HideFromGUI" then chk_manager.Checked = False
      if tr_whencreated.classname="HideFromGUI" then chk_whencreated.Checked = False
      if tr_oupathuser.classname="HideFromGUI" then chk_oupathuser.Checked = False
      if tr_lastlogintimestamp.classname="HideFromGUI" then chk_lastlogintimestamp.Checked = False
      if tr_notes.classname="HideFromGUI" then chk_notes.Checked = False
      if tr_computerserialno.classname="HideFromGUI" then chk_computerserialno.Checked = False
      if tr_replacedmachine.classname="HideFromGUI" then chk_replacedmachine.Checked = False
      if tr_replacedcomputerserialno.classname="HideFromGUI" then chk_replacedcomputerserialno.Checked = False
      if tr_oupathcomputer.classname="HideFromGUI" then chk_oupathcomputer.Checked = False
      if tr_computeros.classname="HideFromGUI" then chk_computeros.Checked = False
      if tr_computerdescription.classname="HideFromGUI" then chk_computerdescription.Checked = False
      if tr_computercreated.classname="HideFromGUI" then chk_computercreated.Checked = False
      if tr_groupmembership.classname="HideFromGUI" then chk_groupmembership.Checked = False
      if tr_dgmembership.classname="HideFromGUI" then chk_dgmembership.Checked = False
      if tr_managerlist.classname="HideFromGUI" then chk_managerlist.Checked = False
      if tr_subordinates.classname="HideFromGUI" then chk_subordinates.Checked = False
End sub
 
Sub Clear_Form(resetGroupLists)
      txt_seatno.Value = ""
      txt_seatno.style.backgroundColor="#FFFFFF"
      txt_seatno.Disabled = False
      txt_replacementseatno.Value = ""
      txt_replacementseatno.style.backgroundColor="#FFFFFF"
      txt_replacementseatno.Disabled = False
      txt_building.Value = ""
      txt_building.style.backgroundColor="#FFFFFF"
      txt_building.Disabled = False
      txt_extensionno.Value = ""
      txt_extensionno.style.backgroundColor="#FFFFFF"
      txt_extensionno.Disabled = False
      txt_empid.Value = ""
      txt_empid.style.backgroundColor="#FFFFFF"
      txt_empid.Disabled = False
      txt_department.Value = ""
      txt_department.style.backgroundColor="#FFFFFF"
      txt_department.Disabled = False
      txt_designation.Value = ""
      txt_designation.style.backgroundColor="#FFFFFF"
      txt_designation.Disabled = False
      txt_name.Value = ""
      txt_name.style.backgroundColor="#FFFFFF"
      txt_name.Disabled = False
      txt_loginname.Value = ""
      txt_loginname.style.backgroundColor="#FFFFFF"
      txt_loginname.Disabled = False
      txt_email.Value = ""
      txt_email.style.backgroundColor="#FFFFFF"
      txt_email.Disabled = False
      txt_mailboxsize.Value = ""
      txt_mailboxsize.style.backgroundColor="#FFFFFF"
      txt_mailboxsize.Disabled = False
      txt_mailboxstore.Value = ""
      txt_mailboxstore.style.backgroundColor="#FFFFFF"
      txt_mailboxstore.Disabled = False
      txt_notes.Value = ""
      txt_notes.style.backgroundColor="#FFFFFF"
      txt_notes.Disabled = False
      txt_computerserialno.Value = ""
      txt_computerserialno.style.backgroundColor="#FFFFFF"
      txt_computerserialno.Disabled = False
      txt_replacedmachine.Value = ""
      txt_replacedmachine.Disabled = False
      txt_replacedmachine.style.backgroundcolor="#FFFFFF"
      txt_replacedcomputerserialno.value = ""
      txt_replacedcomputerserialno.Disabled = False
      txt_replacedcomputerserialno.Style.backgroundcolor="#FFFFFF"
      txt_oupathcomputer.Value = ""
      txt_oupathcomputer.style.backgroundColor="#FFFFFF"
      txt_oupathcomputer.Disabled = False
      txt_computeros.Value = ""
      txt_computeros.Style.backgroundColor="#FFFFFF"
      txt_computeros.Disabled = False
      txt_computerservicepack.Value = ""
      txt_computerservicepack.Style.backgroundColor="#FFFFFF"
      txt_computerservicepack.Disabled = False
      txt_computercreated.Value = ""
      txt_computercreated.Style.backgroundColor="#FFFFFF"
      txt_computercreated.Disabled = False
      txt_computerdescription.Value = ""
      txt_computerdescription.Style.backgroundColor="#FFFFFF"
      txt_computerdescription.Disabled = False
      txt_mobileno.Value = ""
      txt_mobileno.style.backgroundColor="#FFFFFF"
      txt_mobileno.Disabled = False
      txt_company.Value = ""
      txt_company.style.backgroundColor="#FFFFFF"
      txt_company.Disabled = False
      txt_address.Value = ""
      txt_address.style.backgroundColor="#FFFFFF"
      txt_address.Disabled = False
      txt_city.Value = ""
      txt_city.style.backgroundColor="#FFFFFF"
      txt_city.Disabled = False
      txt_state.Value = ""
      txt_state.style.backgroundColor="#FFFFFF"
      txt_state.Disabled = False
      txt_zipcode.Value = ""
      txt_zipcode.style.backgroundColor="#FFFFFF"
      txt_zipcode.Disabled = False
      txt_country.Value = ""
      txt_country.style.backgroundColor="#FFFFFF"
      txt_country.Disabled = False
      txt_homephone.Value = ""
      txt_homephone.style.backgroundColor="#FFFFFF"
      txt_homephone.Disabled = False
      txt_manager.Value = ""
      txt_manager.style.backgroundColor="#FFFFFF"
      txt_manager.Disabled = False
      txt_managerseen.Value = ""
      txt_managerseen.style.backgroundColor="#FFFFFF"
      txt_managerseen.Disabled = False
      txt_whencreated.Value = ""
      txt_whencreated.style.backgroundColor="#FFFFFF"
      txt_whencreated.Disabled = False
      txt_oupathuser.Value = ""
      txt_oupathuser.style.backgroundColor="#FFFFFF"
      txt_oupathuser.Disabled = False
      txt_lastlogintimestamp.Value = ""
      txt_lastlogintimestamp.style.backgroundcolor="#FFFFFF"
      txt_lastlogintimestamp.Disabled = False
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      span_currentrecord.InnerHTML = "0"
      span_totalrecords.InnerHTML = "0"
      span_computerip.InnerHTML = ""
      span_computerOnline.InnerHTML = ""
      span_enabled.InnerHTML = ""
      span_userorcontact.InnerHTML = ""
      if lcase(resetGroupLists) = lcase("resetGroupLists") then
          GroupMembershipDB.Filter = ""
          GroupMembershipDB.MoveFirst
          Do While Not GroupMembershipDB.EOF
              GroupMembershipDB.Delete
              GroupMembershipDB.MoveNext
          Loop
          FillGroupList
      end if
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      FillManagerList
End Sub
 
Sub Submit_Form(btnPush)
 
      arrFields = Array(_
            "txt_seatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_notes", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_oupathuser", _
            "txt_computerserialno", _
            "txt_whencreated", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computercreated" _
      )
      
      boolValid = False
      For Each strField In arrFields
            If Eval(strField & ".Disabled") = True Then
                  boolValid = True
            End If
            If Eval(strField & ".Disabled") = False Then
                  strCurrentField = strField
            End If
      Next
      
      If boolValid = False Then strCurrentField = "INVALID"
      
      Select Case strCurrentField
            Case "txt_seatno"
                  If txt_seatno.Value = "" Then
                  	strSearchField = "(info=*)"
                  Else
                  	strSearchField = "(info=*" & txt_seatno.Value & "*)"
                  End If
            Case "txt_building"
                  If txt_building.Value = "" Then
                  	strSearchField = "(physicalDeliveryOfficeName=*)"
                  Else
                  	strSearchField = "(physicalDeliveryOfficeName=*" & txt_building.Value & "*)"
                  End If
            Case "txt_extensionno"
                  If txt_extensionno.Value = "" Then
                        strSearchField = "(telephoneNumber=*)"
                  Else
                        strSearchField = "(telephoneNumber=*" & txt_extensionno.Value & "*)"
                  End If
            Case "txt_empid"
                  If txt_empid.Value = "" Then
                        strSearchField = "(description=*)"
                  Else
                        strSearchField = "(description=*" & txt_empid.Value & "*)"
                  End If
            Case "txt_department"
                  If txt_department.Value = "" Then
                        strSearchField = "(department=*)"
                  Else
                        strSearchField = "(department=*" & txt_department.Value & "*)"
                  End If
            Case "txt_designation"
                  If txt_designation.Value = "" Then
                        strSearchField = "(title=*)"
                  Else
                        strSearchField = "(title=*" & txt_designation.Value & "*)"
                  End If
            Case "txt_name"
                  If txt_name.Value = "" Then
                        strSearchField = "(cn=*)"
                  Else
                        strSearchField = "(cn=*" & txt_name.Value & "*)"
                  End If
            Case "txt_loginname"
                  If txt_loginname.Value = "" Then
                        strSearchField = "(samAccountName=*)"
                  Else
                        strSearchField = "(samAccountName=*" & txt_loginname.Value & "*)"
                  End If
            Case "txt_email"
                  If txt_email.Value = "" Then
                        strSearchField = "(mail=*)"
                  Else
                        strSearchField = "(mail=*" & txt_email.Value & "*)"
                  End If
            Case "txt_notes"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_notes.Value & "*)"
                  End If
            Case "txt_mobileno"
                  If txt_mobileno.Value = "" Then
                        strSearchField = "(mobile=*)"
                  Else
                        strSearchField = "(mobile=*" & txt_mobileno.Value & "*)"
                  End If
            Case "txt_company"
                  If txt_company.Value = "" Then
                        strSearchField = "(company=*)"
                  Else
                        strSearchField = "(company=*" & txt_company.Value & "*)"
                  End If
            Case "txt_address"
                  If txt_address.Value = "" Then
                        strSearchField = "(streetAddress=*)"
                  Else
                        strSearchField = "(streetAddress=*" & txt_address.Value & "*)"
                  End If
            Case "txt_city"
                  If txt_city.Value = "" Then
                        strSearchField = "(l=*)"
                  Else
                        strSearchField = "(l=*" & txt_city.Value & "*)"
                  End If
            Case "txt_state"
                  If txt_state.Value = "" Then
                        strSearchField = "(st=*)"
                  Else
                        strSearchField = "(st=*" & txt_state.Value & "*)"
                  End If
            Case "txt_zipcode"
                  If txt_zipcode.Value = "" Then
                        strSearchField = "(postalCode=*)"
                  Else
                        strSearchField = "(postalCode=*" & txt_zipcode.Value & "*)"
                  End If
            Case "txt_country"
                  If txt_country.Value = "" Then
                        strSearchField = "(c=*)"
                  Else
                        strSearchField = "(c=*" & txt_country.Value & "*)"
                  End If
            Case "txt_homephone"
                  If txt_homephone.Value = "" Then
                        strSearchField = "(homePhone=*)"
                  Else
                        strSearchField = "(homePhone=*" & txt_homephone.Value & "*)"
                  End If
            Case "txt_managerseen"
                  If txt_managerseen.Value = "" Then
                        strSearchField = "(manager=*)"
                  Else
                        strSearchField = GetManagerDN(txt_managerseen.Value)
                  End If
            Case "txt_oupathuser"
                  If txt_oupathuser.Value <> "" Then
                        strSearchField = GetOUMembers(txt_oupathuser.Value)
                  End If
            Case "txt_whencreated"
                  If txt_whencreated.Value = "" Then
                        strSearchField = "(whenCreated=*)"
                  Else
                        if NOT IsDate(txt_whencreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strWhenCreated = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
                            strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
                        end if
                  End If
            Case "txt_computerserialno"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_computerserialno.Value & "*)"
                  End If
            Case "txt_oupathcomputer"
                  If txt_oupathcomputer.Value = "" then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersBasedOnOU(txt_oupathcomputer.Value)
                  end if
            Case "txt_computeros"
                  If txt_computeros.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersForOSQuery(txt_computeros.Value)
                  End If
            Case "txt_computercreated"
                  If txt_computercreated.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        if NOT IsDate(txt_computercreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strSearchField = GetComputersForDateCreatedQuery(txt_computercreated.Value)
                        End If
                  End If
            Case Else
                  strSearchField = "INVALID"
      End Select
      
      if btnPush = "Disabled" then
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)"
      end if
      
      if btnPush = "Group" then
          For i = 0 to (lst_groupnames.Options.Length - 1)
              If (lst_groupnames.Options(i).Selected) Then
                  arrGroupNames = split(lst_groupnames.Options(i).Value,";")
                  sprimaryGroupID = arrGroupNames(0)
                  sMemberOf = arrGroupNames(1)
              End If
          Next
          if sprimaryGroupID = 513 then
              strSearchField = "(primaryGroupID=" & sprimaryGroupID & ")"
          else
              strSearchField = "(memberOf=" & sMemberOf & ")"
          end if
      end if
      
      if btnPush = "DistributionGroup" then
          For i = 0 to (lst_dgnames.Options.Length - 1)
              If (lst_dgnames.Options(i).Selected) Then
                  arrGroupNames = split(lst_dgnames.Options(i).Value,";")
                  sprimaryGroupID = arrGroupNames(0)
                  sMemberOf = arrGroupNames(1)
              End If
          Next
          if sprimaryGroupID = 513 then
              strSearchField = "(primaryGroupID=" & sprimaryGroupID & ")"
          else
              strSearchField = "(memberOf=" & sMemberOf & ")"
          end if
      end if
      
      if btnPush = "ManagerList" then
          For i = 0 to (lst_ManagerList.Options.Length - 1)
              If (lst_ManagerList.Options(i).Selected) Then
                  strSearchField = "(distinguishedname=" & lst_ManagerList.Options(i).Value & ")" 
              End If
          Next
      end if
      
      if btnPush = "Subordinate" then
          For i = 0 to (lst_subordinates.Options.Length - 1)
              If (lst_subordinates.Options(i).Selected) Then
                  arrSubordinateNames = split(lst_subordinates.Options(i).Value,";")
                  strSearchField = "(samAccountName=*" & arrSubordinateNames(0) & "*)"
              End If
          Next
      end if
      
      if btnPush = "DisabledToday" then
          strWhenChanged = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)(whenChanged>=" & strWhenChanged & "000000.0Z)(whenChanged<=" & strWhenChanged & "235959.0Z)"
      end if
      
      if btnPush = "FileOpen" then
          strSearchField = globalStrSearchField
          btnPush = globalStrSearchBtnPush
      End if
      
      boolLogonSearch = False
      dmtDateToCompare = Date()
      
      if InStr(btnPush,"Logon:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolLogonSearch = True
          intNumberOfDays = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
          dmtDateToCompare = Date() - intNumberOfDays
          
          if NOT chk_LookupLastLogin.Checked then
              chk_LookupLastLogin.Checked = True
              boolLookupLastLogin = True
          end if
          
      end if
      
      boolMailboxSizeSearch = False
      
      if InStr(btnPush,"MailboxSize:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolMailboxSizeSearch = True
          intMailboxSizeToCompare = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
      end if
      
      Clear_Form ""
      
      If strSearchField <> "INVALID" Then
            Set adoCommand = CreateObject("ADODB.Command")
            Set adoConnection = CreateObject("ADODB.Connection")
            adoConnection.Provider = "ADsDSOObject"
            adoConnection.Open "Active Directory Provider"
            adoCommand.ActiveConnection = adoConnection
            
            boolFoundRecords = False
            
            for each strDomain in arrDomainNames
                  ' Search entire Active Directory domain.
                  strBase = "<LDAP://" & strDomain & ">"
                  
                  strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
 
                  ' Comma delimited list of attribute values to retrieve.
                  if boolLookupLastLogin then
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID,lastLogon"
                  else
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID"
                  end if
                  ' Construct the LDAP syntax query.
                  strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                  adoCommand.CommandText = strQuery
                  adoCommand.Properties("Page Size") = 100
                  adoCommand.Properties("Timeout") = 30
                  adoCommand.Properties("Cache Results") = False
                  adoCommand.Properties("Sort On") = "cn"
                  ' Run the query.
                  Set adoRecordset = adoCommand.Execute
                  ' Enumerate the resulting recordset.
                  strDetails = ""
                  If Not adoRecordset.EOF Then
                        boolFoundRecords = True
                        Do Until adoRecordset.EOF
                              mailboxlist.filter = "legacyExchangeDN = '" & adoRecordset.Fields("legacyExchangeDN").Value & "'"
                              if NOT mailboxlist.EOF then
                                    intMailboxSize = mailboxlist.fields.Item("mailboxsize")
                              else
                                    intMailboxSize = "0"
                              End if
                              if boolLookupLastLogin then
                                    if NOT IsNull(adoRecordset.Fields("lastLogon").Value) then
                                          Set objLastLogon = adoRecordset.Fields("lastLogon").Value
                                          intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart 
                                          intLastLogonTime = intLastLogonTime / (60 * 10000000)
                                          intLastLogonTime = intLastLogonTime / 1440
                                          intLastLogonTime = intLastLogonTime + #1/1/1601#
                                          if intLastLogonTime = #1/1/1601# then
                                                intLastLogonTime = ""
                                          end if
                                    else
                                          intLastLogonTime = ""
                                    end if
                              else
                                    intLastLogonTime = ""
                              end if
                              if NOT IsDate(intLastLogonTime) then
                                    dmtDateToCompareTo = dmtDateToCompare
                              else
                                    dmtDateToCompareTo = intLastLogonTime
                              end if
                              if (CDate(dmtDateToCompareTo) >= CDate(dmtDateToCompare)) AND boolLogonSearch then
                                    'Do nothing
                              else
                                    if (CInt(intMailboxSize) < CInt(intMailboxSizeToCompare)) AND boolMailboxSizeSearch then
                                          'Do nothing
                                    else
                                          If strDetails <> "" Then strDetails = strDetails & "|TR|"
                                          if adoRecordset.Fields("userAccountControl").Value AND 2 then
                                                strEnabled = "Disabled"
                                          else
                                                strEnabled = "Enabled"
                                          End If
                                          strMachineName = ""
                                          strBuilding = ""
                                          strSerialNumber = ""
                                          If IsNull(adoRecordset.Fields("Info").Value) = False Then
                                                arrNotesField = Split(adoRecordset.Fields("Info").Value,vbCRLF)
                                                for each strLine in arrNotesField
                                                      if InStr(UCase(strLine),"MACHINE NAME : ") then
                                                            strMachineName = trim(mid(strLine,15))
                                                      End if
                                                      if InStr(UCase(strLine),"LOCATION : ") then
                                                            strBuilding = trim(mid(strLine,11))
                                                      End if
                                                      if InStr(UCase(strLine),"SERIAL NO : ") then
                                                            strSerialNumber = trim(mid(strLine,12))
                                                      End if
                                                next
                                                strDetails = strDetails & replace(strBuilding,vbCRLF,"")
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("physicalDeliveryOfficeName").Value &_
                                          "|TD|" & adoRecordset.Fields("TelephoneNumber").Value
                                          If IsNull(adoRecordset.Fields("Description").Value) = False Then
                                                strDetails = strDetails & "|TD|" & Join(adoRecordset.Fields("description").Value)
                                          Else
                                                strDetails = strDetails & "|TD|"
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("Department").Value &_
                                          "|TD|" & adoRecordset.Fields("Title").Value &_
                                          "|TD|" & Replace(adoRecordset.Fields("cn").Value, "CN=", "") &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("mail").Value &_
                                          "|TD|" & strMachineName &_
                                          "|TD|" & adoRecordset.Fields("Mobile").Value &_
                                          "|TD|" & adoRecordset.Fields("company").Value &_
                                          "|TD|" & adoRecordset.Fields("streetAddress").Value &_
                                          "|TD|" & adoRecordset.Fields("l").Value &_
                                          "|TD|" & adoRecordset.Fields("st").Value &_
                                          "|TD|" & adoRecordset.Fields("postalCode").Value &_
                                          "|TD|" & adoRecordset.Fields("c").Value &_
                                          "|TD|" & adoRecordset.Fields("homePhone").Value &_
                                          "|TD|" & adoRecordset.Fields("manager").Value &_
                                          "|TD|" & adoRecordset.Fields("whenCreated").Value &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("distinguishedName").Value &_
                                          "|TD|" & intLastLogonTime &_
                                          "|TD|" & strSerialNumber &_
                                          "|TD|" & UCASE(strEnabled) &_
                                          "|TD|" & intMailboxSize &_
                                          "|TD|" & adoRecordset.Fields("homeMDB").Value &_
                                          "|TD|" & adoRecordset.Fields("primaryGroupID").Value
                                          strDetails = replace(strDetails,vbCRLF,"")
                                    end if
                              end if
                              adoRecordset.MoveNext
                        Loop
                  End If
            next
            
            if NOT boolFoundRecords then
                  MsgBox "No records were found"
            End if
            
            ' Clean up.
            adoRecordset.Close
            Set adoRecordset = Nothing
            
            adoConnection.Close
      
            If strDetails <> "" Then
                  arrRows = ""
                  arrRows = Split(strDetails, "|TR|")
                  If UBound(arrRows) < 0 Then
                        span_currentrecord.InnerHTML = 0
                        span_totalrecords.InnerHTML = 0
                  Else
                        span_currentrecord.InnerHTML = 1
                        Get_Event
                        span_totalrecords.InnerHTML = UBound(arrRows)+1
                  End If
            Else
                  span_currentrecord.InnerHTML = 0
                  span_totalrecords.InnerHTML = 0
            End If
            If strDetails = "" Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = True
                  btnEMailAllRecords.Disabled = True
                  btnEmailAsAttachment.Disabled = True
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Hidden"
                  btnEMailAllRecords.Style.Visibility = "Hidden"
                  btnEmailAsAttachment.Style.Visibility = "Hidden"
            ElseIf UBound(arrRows) = 0 Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            Else
                  btnFirstEvent.Disabled = False
                  btnPreviousEvent.Disabled = False
                  btnNextEvent.Disabled = False
                  btnLastEvent.Disabled = False
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Visible"
                  btnPreviousEvent.Style.Visibility = "Visible"
                  btnNextEvent.Style.Visibility = "Visible"
                  btnLastEvent.Style.Visibility = "Visible"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            End If
            globalStrSearchBtnPush = BtnPush
            globalstrSearchField = strSearchField
            if chk_qbrecorder.Checked then
                  AddToQueryBuilder
            end if
      Else
            MsgBox "Please type a search request into one of the fields, then click Submit."
      End If
 
      if InStr(Join(arrFields),strCurrentField) then
            if strSearchField <> "INVALID" then
                  execute(strCurrentField & ".focus")
                  execute(strCurrentField & ".select()")
            end if
      end if
End Sub
 
Sub Get_Event
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	txt_seatno.Value = arrData(0)
	txt_building.Value = arrData(1)
	txt_extensionno.Value = arrData(2)
	txt_empid.Value = arrData(3)
	txt_department.Value = arrData(4)
	txt_designation.Value = arrData(5)
	txt_name.Value = arrData(6)
	txt_loginname.Value = arrData(7)
	txt_email.Value = arrData(8)
        txt_mailboxsize.Value = arrData(25)
        txt_mailboxstore.Value = arrData(26)
	txt_notes.Value = arrData(9)
        if boolAllowPing then PingComputer arrData(9)
        txt_computerserialno.Value = arrData(23)
        arrTemp = GetComputerInfo(arrData(9))
	if IsArray(arrTemp) then
	        txt_oupathcomputer.value = GetOUPath(replace(arrTemp(0),"""",""))
	        txt_computeros.value = replace(arrTemp(1),"""","")
	        txt_computerservicepack.value = replace(arrTemp(2),"""","")
	        txt_computerdescription.value = replace(arrTemp(4),"""","")
	        txt_computercreated.value = replace(arrTemp(3),"""","")
	else
	        txt_oupathcomputer.value = ""
	        txt_computeros.value = ""
	        txt_computerservicepack.value = ""
	        txt_computerdescription.value = ""
	        txt_computercreated.value = ""
	End if
	txt_mobileno.Value = arrData(10)
	txt_company.Value = arrData(11)
	txt_address.Value = arrData(12)
	txt_city.Value = arrData(13)
	txt_state.Value = arrData(14)
	txt_zipcode.Value = arrData(15)
	txt_country.Value = arrData(16)
	txt_homephone.Value = arrData(17)
	txt_manager.Value = arrData(18)
        For Each objOption in lst_managerlist.Options
            objOption.RemoveNode
        Next
        span_managerlist.InnerHTML = "(0)"
        if txt_manager.Value <> "" then
            txt_managerseen.Value = mid(txt_manager.Value,4,instr(txt_manager.Value,",")-4)
            set newOption = document.createElement("OPTION")
            newOption.Text = txt_managerseen.Value & " (" & GetSubordinateNumbers(txt_manager.Value) & ")"
            newOption.Value = txt_manager.Value
            lst_managerlist.Add newOption
            span_managerlist.InnerHTML = "(1)"
        else
            txt_managerseen.Value = txt_manager.Value
        end if
	txt_whencreated.Value = arrData(19)
        txt_oupathuser.value = GetOUPath(arrData(21))
        txt_lastlogintimestamp.value = arrData(22)
        span_enabled.InnerHTML = arrData(24)
        if txt_loginname.Value <> "" then
            span_userorcontact.InnerHTML = "USER"
        else
            span_userorcontact.InnerHTML = "CONTACT"
        end if
        FillGroupMembershipList arrData(21), arrData(27)
End Sub
 
Sub First_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML < 1 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = 1 Then
                  MsgBox "You are already viewing the first record."
            Else
                  span_currentrecord.InnerHTML = 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Previous_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_currentrecord.InnerHTML > 1 Then
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML - 1
                  Get_Event
            ElseIf span_currentrecord.InnerHTML = 1 Then
                        MsgBox "You are already viewing the first record."
            Else
                  MsgBox "There are no records to display"
            End If
      End If
 
End Sub
 
Sub Next_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records for to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                  MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML + 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Last_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                        MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_totalrecords.InnerHTML
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Detect_Search_Field(strCurrentField)
      arrFields = Array(_
            "txt_seatno", _
            "txt_replacementseatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_mailboxsize", _
            "txt_mailboxstore", _
            "txt_notes", _
            "txt_computerserialno", _
            "txt_replacedmachine", _
            "txt_replacedcomputerserialno", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computerservicepack", _
            "txt_computerdescription", _
            "txt_computercreated", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_whencreated", _
            "txt_oupathuser", _
            "txt_lastlogintimestamp" _
      )
      
      For Each strField In arrFields
            If LCase(strField) <> LCase(strCurrentField) Then
                  Execute strField & ".style.backgroundColor=""#D3D3D3"""
                  Execute strField & ".Disabled = True"
            End If
      Next
End Sub
 
Function CreateHeaderRow(CSVorTABLE)
    Dim arrHeader()
    x = 0
    if chk_seatno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Seat No"""
        x = x + 1
    end if
    
    if chk_building.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Building"""
        x = x + 1
    end if
    
    if chk_extensionno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Extension"""
        x = x + 1
    end if
    
    if chk_empid.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Emp ID"""
        x = x + 1
    end if
    
    if chk_department.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Department"""
        x = x + 1
    end if
    
    if chk_designation.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Designation"""
        x = x + 1
    end if
         
    if chk_name.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """User Name"""
        x = x + 1
    end if
    
    if chk_loginname.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Login Name"""
        x = x + 1
    end if
    
    if chk_email.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Email Address"""
        x = x + 1
    end if
    
    if chk_mailboxsize.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Size (MB)"""
        x = x + 1
    end if
    
    if chk_mailboxstore.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Store"""
        x = x + 1
    end if
    
    if chk_notes.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer"""
        x = x + 1
    end if
    
    if chk_computerserialno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Serial No"""
        x = x + 1
    end if
    
    if chk_oupathcomputer.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - Computer"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer OS"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Service Pack"""
        x = x + 1
    end if
    
    if chk_computerdescription.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Description"""
        x = x + 1
    end if
    
    if chk_computercreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Account Created"""
        x = x + 1
    end if
    
    if chk_mobileno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mobile"""
        x = x + 1
    end if
    
    if chk_company.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Company"""
        x = x + 1
    end if
    
    if chk_address.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Address"""
        x = x + 1
    end if
    
    if chk_city.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """City"""
        x = x + 1
    end if
    
    if chk_state.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """State"""
        x = x + 1
    end if
    
    if chk_zipcode.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Zip Code"""
        x = x + 1
    end if
    
    if chk_country.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Country"""
        x = x + 1
    end if
    
    if chk_homephone.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Home Phone"""
        x = x + 1
    end if
    
    if chk_manager.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Manager"""
        x = x + 1
    end if
    
    if chk_subordinates.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Subordinates"""
        x = x + 1
    end if
    
    if chk_whencreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Date Created"""
        x = x + 1
    end if
    
    if chk_oupathuser.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - User"""
        x = x + 1
    end if
    
    if chk_lastlogintimestamp.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Last Logon"""
        x = x + 1
    end if
    
    if chk_groupmembership.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Group Membership"""
        x = x + 1
    end if
 
    if CSVorTABLE <> "" then
        strHeader = strHeader & "<tr>"
        for n = 0 to UBound(arrHeader)-1
            strHeader = strHeader & "<td valign=""top"" align=""left""><b>" & replace(arrHeader(n),"""","") & "</b></td>"
        next
        strHeader = strHeader & "</tr>" & vbCRLF
    else
        strHeader = Join(arrHeader,",")
    end if
    CreateHeaderRow = strHeader
End Function
 
Function PopulateTableForCSV(CSVorTABLE)
    For intRow = LBound(arrRows) To UBound(arrRows)
        arrData = Split(arrRows(intRow), "|TD|")
        x = 0
        if chk_seatno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(0) & """"
            x = x + 1
        end if
        
        if chk_building.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(1) & """"
            x = x + 1
        end if
        
        if chk_extensionno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(2) & """"
            x = x + 1
        end if
        
        if chk_empid.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(3) & """"
            x = x + 1
        end if
        
        if chk_department.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(4) & """"
            x = x + 1
        end if
         
        if chk_designation.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(5) & """"
            x = x + 1
        end if
        
        if chk_name.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(6) & """"
            x = x + 1
        end if
        
        if chk_loginname.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(7) & """"
            x = x + 1
        end if
        
        if chk_email.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(8) & """"
            x = x + 1
        end if
        
        if chk_mailboxsize.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(25) & """"
            x = x + 1
        end if
        
        if chk_mailboxstore.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(26) & """"
            x = x + 1
        end if
        
        if chk_notes.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(9) & """"
            x = x + 1
        end if
        
        if chk_computerserialno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(23) & """"
            x = x + 1
        end if
        
        arrTemp = GetComputerInfo(arrData(9))
        if IsArray(arrTemp) then
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & GetOUPath(replace(arrTemp(0),"""","")) & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(1),"""","") & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(2),"""","") & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(4),"""","") & """"
                x = x + 1
            end if
	 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(3),"""","") & """"
                x = x + 1
            end if
 
        else
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
        end if
        
        if chk_mobileno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(10) & """"
            x = x + 1
        end if
        
        if chk_company.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(11) & """"
            x = x + 1
        end if
        
        if chk_address.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(12) & """"
            x = x + 1
        end if
        
        if chk_city.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(13) & """"
            x = x + 1
        end if
        
        if chk_state.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(14) & """"
            x = x + 1
        end if
        
        if chk_zipcode.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(15) & """"
            x = x + 1
        end if
        
        if chk_country.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(16) & """"
            x = x + 1
        end if
        
        if chk_homephone.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(17) & """"
            x = x + 1
        end if
        
        if chk_manager.Checked then
            ReDim Preserve arrFileData(x)
            if arrData(18) <> "" then
                arrFileData(x) = """" & mid(arrData(18),4,instr(arrData(18),",")-4) & """"
            else
                arrFileData(x) = """" & """"
            end if
            x = x + 1
        end if
        
        if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
                
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
                
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
                
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = ""
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & str_subordinates & """"
                x = x + 1
            next
        end if
        
        if chk_whencreated.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(19) & """"
            x = x + 1
        end if
        
        if chk_oupathuser.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & GetOUPath(arrData(21)) & """"
            x = x + 1
        end if
        
        if chk_lastlogintimestamp.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(22) & """"
            x = x + 1
        end if
        
        if chk_groupmembership.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & ReportGroupMemberShipList(arrData(21), arrData(27)) & """"
            x = x + 1
        end if
 
        if CSVorTABLE <> "" then
            strFileData = strFileData & "<tr>"
            for n = 0 to UBound(arrFileData)-1
                strEntry = replace(arrFileData(n),"""","")
                if strEntry = "" then strEntry = "&nbsp;"
                strFileData = strFileData & "<td valign=""top"" align=""left"">" & strEntry & "</td>"
            next
            strFileData = strFileData & "</tr>" & vbCRLF
        else
            strFileData = strFileData & Join(arrFileData,",") & vbCRLF
        end if
    Next
    PopulateTableForCSV = strFileData
End Function 
 
Sub RunScript
      on error resume next
      Dim oDLG
      Set oDLG=CreateObject("MSComDlg.CommonDialog")
      if err.number > 0 then
          err.clear
          oDLG = window.prompt("Please enter the path and file name to save.", "D:\HTA-Result-Set.csv")
              if oDLG <> "" then
                  strAnswer = oDLG
              End If
      else
          With oDLG
              .DialogTitle = "Save As"
              .Filter="CSV File|*.csv"
              .MaxFileSize = 255
              .ShowSave
              If .FileName <> "" Then
                  strAnswer = .FileName
              End If
          End With
      end if
      Set oDLG=Nothing
 
      If IsNull(strAnswer) or strAnswer = "" Then
        'Do nothing
      Else
        if globalstrSearchBtnPush <> "" then
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            end if
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write CreateHeaderRow("") & vbCRLF
            objFile.Write PopulateTableForCSV("")
            objFile.Close
            MsgBox "Saved."
        else
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            Else
                ' do nothing
            end if
 
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write """Security Groups""" & VbCrLf
            For Each objOption in lst_groupnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Write """Distribution Groups""" & VbCrLf
            For Each objOption in lst_dgnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Close
            MsgBox "Saved."
        End if
      End If
End Sub
 
Sub Email_This_Record
 
        ShowDialogTo
        ShowDialogCC
   
        ConvertNamesToEmailAddresses
	
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	
        if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & txt_seatno.value & "<br>" & vbCRLF
	else
		str_seatno      = ""
	end if
 
        if chk_replacementseatno.Checked then
		str_replacementseatno      = "<b>These are the replacement details</b><br><b>Seat No: </b>" & txt_replacementseatno.value & "<br>" & vbCRLF
	else
		str_replacementseatno      = ""
	end if
 
	if chk_building.Checked then
		str_building    = "<b>Building: </b>" & txt_building.value &  "<br>" & vbCRLF
	else
		str_building    = ""
	end if
 
	if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & txt_extensionno.value &  "<br>" & vbCRLF
	else
		str_extensionno = ""
	end if
 
	if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & txt_empid.value &  "<br>" & vbCRLF
	else
		str_empid       = ""
	end if
 
	if chk_department.Checked then
		str_department  = "<b>Department: </b>" & txt_department.value &  "<br>" & vbCRLF
	else
		str_department  = ""
	end if
 
	if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & txt_designation.value &  "<br>" & vbCRLF
	else
		str_designation = ""
	end if
 
	if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & txt_name.value &  "<br>" & vbCRLF
	else
		str_name        = ""
	end if
 
	if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & txt_loginname.value &  "<br>" & vbCRLF
	else
		str_loginname   = ""
	end if
 
	if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & txt_email.value &  "<br>" & vbCRLF
	else
		str_email       = ""
	end if
 
	if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & txt_mailboxsize.value &  "<br>" & vbCRLF
	else
		str_mailboxsize       = ""
	end if
 
	if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & txt_mailboxstore.value &  "<br>" & vbCRLF
	else
		str_mailboxstore       = ""
	end if
 
	if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & txt_notes.value &  "<br>" & vbCRLF
	else
		str_notes       = ""
	end if
 
	if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & txt_computerserialno.value &  "<br>" & vbCRLF
	else
		str_computerserialno       = ""
	end if
 
	if chk_replacedmachine.Checked then
		str_replacedmachine       = "<b>These are the replacement details</b><br><b>Machine Name: </b>" & txt_replacedmachine.value &  "<br>" & vbCRLF
	else
		str_replacedmachine       = ""
	end if
 
	if chk_replacedcomputerserialno.Checked then
		str_replacedcomputerserialno       = "<b>Replaced Serial No: </b>" & txt_replacedcomputerserialno.value &  "<br>" & vbCRLF
	else
		str_replacedcomputerserialno       = ""
	end if
 
 
        arrTemp = GetComputerInfo(arrData(9))
 	if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & txt_oupathcomputer.value &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & txt_computeros.value &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & txt_computerservicepack.value &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & txt_computerdescription.value &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & txt_computercreated.value &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	end if
 
	if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & txt_mobileno.value &  "<br>" & vbCRLF
	else
		str_mobileno    = ""
	end if
 
	if chk_company.Checked then
		str_company     = "<b>Company: </b>" & txt_company.value &  "<br>" & vbCRLF
	else
		str_company     = ""
	end if
 
	if chk_address.Checked then
		str_address     = "<b>Address: </b>" & txt_address.value &  "<br>" & vbCRLF
	else
		str_address     = ""
	end if
 
	if chk_city.Checked then
		str_city        = "<b>City: </b>" & txt_city.value &  "<br>" & vbCRLF
	else
		str_city        = ""
	end if
 
	if chk_state.Checked then
		str_state       = "<b>State: </b>" & txt_state.value &  "<br>" & vbCRLF
	else
		str_state       = ""
	end if
 
	if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & txt_zipcode.value &  "<br>" & vbCRLF
	else
		str_zipcode     = ""
	end if
 
	if chk_country.Checked then
		str_country     = "<b>Country: </b>" & txt_country.value &  "<br>" & vbCRLF
	else
		str_country     = ""
	end if
 
	if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & txt_homephone.value &  "<br>" & vbCRLF
	else
		str_homephone   = ""
	end if
 
	if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
	else
		str_manager   = ""
	end if
 
	if chk_subordinates.Checked then
            str_subordinates = "<b>Subordinates: </b>"
            boolFoundFirst = False
            str_subordinates = ""
            For Each objOption in lst_subordinates.Options
                if boolFoundFirst then
                    str_subordinates = str_subordinates & ", " & objOption.Text
                else
                    boolFoundFirst = True
                    str_subordinates = str_subordinates & objOption.Text
                end if
            Next
            str_subordinates = str_subordinates &  "<br>" & vbCRLF
	else
            str_subordinates = ""
	end if
  
	if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & txt_whencreated.value &  "<br>" & vbCRLF
	else
		str_whencreated = ""
	end if
  
	if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & txt_oupathuser.value &  "<br>" & vbCRLF
	else
		str_oupathuser       = ""
	end if
  
	if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & txt_lastlogintimestamp.value &  "<br>" & vbCRLF
	else
		str_lastlogintimestamp       = ""
	end if
 
	if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
	else
		str_groupmembership       = ""
	end if
 
        str_message = str_seatno & _
            str_replacementseatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_replacedmachine & _
            str_replacedcomputerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership
 
      if trim(txt_EmailSubject.value) = "" then
          strEmailSubject = "Active Directory Detail Report"
      else
          strEmailSubject = trim(txt_EmailSubject.value)
      end if
 
        Set objMessage = CreateObject("CDO.Message")
        objMessage.From = strEmailFrom
        objMessage.To = strEmailTo
        objMessage.CC = strEmailCC
        objMessage.BCC = strEmailBCC
        objMessage.Subject = strEmailSubject
        objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
        objMessage.Configuration.Fields.Update
        objMessage.Send
 
        MsgBox "An email has been sent"
 
End Sub
 
Sub Email_All_Records
 
    ShowDialogTo
    ShowDialogCC
   
    ConvertNamesToEmailAddresses
 
    str_message = ""
    if boolTableReports then
        str_message = str_message & "<table width=""100%"" border=""1"">" & vbCRLF
        str_message = str_message & CreateHeaderRow("Table") & vbCRLF
        str_message = str_message & PopulateTableForCSV("Table") & vbCRLF
        str_message = str_message & "</table>" & vbCRLF
    else
        for n = 0 to UBound(arrRows)
	    arrData = Split(arrRows(n), "|TD|")
 
            if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & arrData(0) &  "<br>" & vbCRLF
	    else
		str_seatno      = ""
            end if
 
            if chk_building.Checked then
		str_building    = "<b>Building: </b>" & arrData(1) &  "<br>" & vbCRLF
            else
		str_building    = ""
            end if
 
            if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & arrData(2) &  "<br>" & vbCRLF
            else
		str_extensionno = ""
            end if
 
            if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & arrData(3) &  "<br>" & vbCRLF
            else
		str_empid       = ""
            end if
 
            if chk_department.Checked then
		str_department  = "<b>Department: </b>" & arrData(4) &  "<br>" & vbCRLF
            else
		str_department  = ""
            end if
 
            if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & arrData(5) &  "<br>" & vbCRLF
            else
		str_designation = ""
            end if
 
            if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & arrData(6) &  "<br>" & vbCRLF
            else
		str_name        = ""
            end if
 
            if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & arrData(7) &  "<br>" & vbCRLF
            else
		str_loginname   = ""
            end if
 
            if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & arrData(8) &  "<br>" & vbCRLF
            else
		str_email       = ""
            end if
 
            if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & arrData(25) &  "<br>" & vbCRLF
            else
		str_mailboxsize       = ""
            end if
 
            if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & arrData(26) &  "<br>" & vbCRLF
            else
		str_mailboxstore       = ""
            end if
 
            if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & arrData(9) &  "<br>" & vbCRLF
            else
		str_notes       = ""
            end if
 
            if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & arrData(23) &  "<br>" & vbCRLF
            else
		str_computerserialno       = ""
            end if
 
            arrTemp = GetComputerInfo(arrData(9))
            if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & GetOUPath(replace(arrTemp(0),"""","")) &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & replace(arrTemp(1),"""","") &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & replace(arrTemp(2),"""","") &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & replace(arrTemp(4),"""","") &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & replace(arrTemp(3),"""","") &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            end if
 
            if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & arrData(10) &  "<br>" & vbCRLF
            else
		str_mobileno    = ""
            end if
 
            if chk_company.Checked then
		str_company     = "<b>Company: </b>" & arrData(11) &  "<br>" & vbCRLF
            else
		str_company     = ""
            end if
 
            if chk_address.Checked then
		str_address     = "<b>Address: </b>" & arrData(12) &  "<br>" & vbCRLF
            else
		str_address     = ""
            end if
 
            if chk_city.Checked then
		str_city        = "<b>City: </b>" & arrData(13) &  "<br>" & vbCRLF
            else
		str_city        = ""
            end if
 
            if chk_state.Checked then
		str_state       = "<b>State: </b>" & arrData(14) &  "<br>" & vbCRLF
            else
		str_state       = ""
            end if
 
            if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & arrData(15) &  "<br>" & vbCRLF
            else
		str_zipcode     = ""
            end if
 
            if chk_country.Checked then
		str_country     = "<b>Country: </b>" & arrData(16) &  "<br>" & vbCRLF
            else
		str_country     = ""
            end if
 
            if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & arrData(17) &  "<br>" & vbCRLF
            else
		str_homephone   = ""
            end if
 
            if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
            else
		str_manager   = ""
            end if
 
            if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
   
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
    
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = "<b>Subordinates: </b>"
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                str_subordinates = str_subordinates &  "<br>" & vbCRLF
            next
            else
		str_subordinates = ""
            end if
 
            if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & arrData(19) &  "<br>" & vbCRLF
            else
		str_whencreated = ""
            end if
    
            if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & GetOUPath(arrData(21)) &  "<br>" & vbCRLF
            else
		str_oupathuser       = ""
            end if
    
            if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & arrData(22) &  "<br>" & vbCRLF
            else
		str_lastlogintimestamp       = ""
            end if
  
 
            if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
            else
		str_groupmembership       = ""
            end if
 
            str_message = str_message & _
            str_seatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership & VbCrLf & "<br><hr><br><br>" & vbCRLF
        next
    end if
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom 
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
    objMessage.Configuration.Fields.Update
    objMessage.Send
    
    MsgBox "An email has been sent"
    
End Sub
 
Sub Email_As_Attachment
    
    ShowDialogTo
    ShowDialogCC
    
    ConvertNamesToEmailAddresses
    
    strAnswer = fTemp & "\HTAResults.csv"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(strAnswer) = True Then
        objFSO.DeleteFile strAnswer, True
    end if
    Set objFile = objFSO.CreateTextFile(strAnswer, True)
    objFile.Write CreateHeaderRow("") & vbCRLF
    objFile.Write PopulateTableForCSV("")
    objFile.Close
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.TextBody = trim(txt_EmailBody.value) & vbCRLF & vbCRLF
    
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    
    objMessage.Configuration.Fields.Update
    objMessage.AddAttachment strAnswer
    objMessage.Send
    
    MsgBox "An email has been sent"
    objFSO.DeleteFile strAnswer, True
    
End Sub
 
Sub SelectAllCheck
	If chk_selectall.Checked then
		CheckAllBoxes
                TestToSeeWhatLinesAreHidden
	else
		UnCheckAllBoxes
	end if
End Sub
 
Sub UnCheckAllBoxes
	chk_selectall.Checked = False
	chk_seatno.Checked = False
	chk_replacementseatno.Checked = False
	chk_building.Checked = False
	chk_extensionno.Checked = False
	chk_seatno.Checked = False
	chk_empid.Checked = False
	chk_department.Checked = False
	chk_designation.Checked = False
	chk_name.Checked = False
	chk_loginname.Checked = False
	chk_email.Checked = False
	chk_mailboxsize.Checked = False
	chk_mailboxstore.Checked = False
	chk_notes.Checked = False
	chk_computerserialno.Checked = False
	chk_replacedmachine.Checked = False
	chk_replacedcomputerserialno.Checked = False
	chk_oupathcomputer.Checked = False
	chk_computeros.Checked = False
	chk_computerdescription.Checked = False
	chk_computercreated.Checked = False
	chk_mobileno.Checked = False
	chk_company.Checked = False
	chk_address.Checked = False
	chk_city.Checked = False
	chk_state.Checked = False
	chk_zipcode.Checked = False
	chk_country.Checked = False
	chk_homephone.Checked = False
	chk_manager.Checked = False
	chk_whencreated.Checked = False
	chk_oupathuser.Checked = False
	chk_lastlogintimestamp.Checked = False
	chk_groupmembership.Checked = False
	chk_dgmembership.Checked = False
	chk_managerlist.Checked = False
	chk_subordinates.Checked = False
End Sub
 
Sub CheckAllBoxes
	chk_selectall.Checked = True
	chk_seatno.Checked = True
	chk_replacementseatno.Checked = True
	chk_building.Checked = True
	chk_extensionno.Checked = True
	chk_empid.Checked = True
	chk_department.Checked = True
	chk_designation.Checked = True
	chk_name.Checked = True
	chk_loginname.Checked = True
	chk_email.Checked = True
	chk_mailboxsize.Checked = True
	chk_mailboxstore.Checked = True
	chk_notes.Checked = True
	chk_computerserialno.Checked = True
	chk_replacedmachine.Checked = True
	chk_replacedcomputerserialno.Checked = True
	chk_oupathcomputer.Checked = True
	chk_computeros.Checked = True
	chk_computerdescription.Checked = True
	chk_computercreated.Checked = True
	chk_mobileno.Checked = True
	chk_company.Checked = True
	chk_address.Checked = True
	chk_city.Checked = True
	chk_state.Checked = True
	chk_zipcode.Checked = True
	chk_country.Checked = True
	chk_homephone.Checked = True
	chk_manager.Checked = True
	chk_whencreated.Checked = True
	chk_oupathuser.Checked = True
	chk_lastlogintimestamp.Checked = True
	chk_groupmembership.Checked = True
	chk_dgmembership.Checked = True
	chk_managerlist.Checked = True
	chk_subordinates.Checked = True
End Sub
 
Function GetUsersEmailAddress
	Set oNet = CreateObject("WScript.NetWork")
	sSearchField = "(samAccountName=*" & oNet.UserName & "*)"
	Set objRootDSE = GetObject("LDAP://RootDSE")
	sDNSDomain = objRootDSE.Get("defaultNamingContext")
	sBase = "<LDAP://" & sDNSDomain & ">"
	sFilter = "(&(objectCategory=person)(objectClass=user)" & sSearchField & ")"
	sAttributes = "cn,samAccountName,mail"
	sQuery = sBase & ";" & sFilter & ";" & sAttributes & ";subtree"
	Set aCommand = CreateObject("ADODB.Command")
	Set aConnection = CreateObject("ADODB.Connection")
	aConnection.Provider = "ADsDSOObject"
	aConnection.Open "Active Directory Provider"
	aCommand.ActiveConnection = aConnection
	aCommand.CommandText = sQuery
	aCommand.Properties("Page Size") = 100
	aCommand.Properties("Timeout") = 30
	aCommand.Properties("Cache Results") = False
	Set aRecordset = aCommand.Execute
 
	GetUsersEmailAddress = aRecordset.Fields("cn").Value
 
End Function
 
Sub ShowDialogCC
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailCC.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailCC.Value = strValidEmail
End Sub
 
Sub ShowDialogTo
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailTo.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailTo.Value = strValidEmail
End Sub
 
Sub ShowDialogFrom
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailFrom.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailFrom.Value = strValidEmail
End Sub
 
Sub FillGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    on error resume next
    For Each objOption in lst_groupnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_dgnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
    
    ' This section is to pull group membership names
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
        strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
        strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
 
        if strLastGroupDN <> strdistinguishedName then
            Select Case strGroupType
                Case "[GDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[LDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[UDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[GSG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[LSG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[USG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[Unknown]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
            End Select
            strLastGroupDN = strdistinguishedName
        End if
        GroupMembershipDB.MoveNext
    Loop
    
    ' This section is to pull subordinate names
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoConnection = CreateObject("ADODB.Connection")
    Set adoCommand = CreateObject("ADODB.Command")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    Set adoCommand.ActiveConnection = adoConnection
 
    strSearchField = "(manager=" & usersDistinguishedname & ")"
    strBase = "<LDAP://" & strDNSDomain & ">"
    strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
    ' Comma delimited list of attribute values to retrieve.
    strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
    
    ' Construct the LDAP syntax query.
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
 
    ' Run the query.
    Set adoRecordset = adoCommand.Execute
 
    Do Until adoRecordset.EOF
        set newOption = document.createElement("OPTION")
        newOption.Text = adoRecordset.Fields("cn").Value & " (" & GetSubordinateNumbers(adoRecordset.Fields("distinguishedName").Value) & ")"
        newOption.Value = adoRecordset.Fields("samAccountName").Value & ";" & adoRecordset.Fields("distinguishedName").Value
        lst_subordinates.Add newOption
        adoRecordset.MoveNext
        intsubordinates = intsubordinates + 1
    Loop
    
    span_groupmembership.InnerHTML = "(" & intGroupMembership & ")"
    span_dgmembership.InnerHTML    = "(" & intdgmembership & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Function ReportGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        if strLastGroupDN <> strdistinguishedName then
            strGroupType  = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName     = GroupMembershipDB.Fields.Item("samaccountname").Value
            strValue      = strValue & strNTName & " " & strGroupType & ";"
            strLastGroupDN = strdistinguishedName
            GroupMembershipDB.MoveNext
        End if
    Loop
    strValue = mid(strValue,1,len(strValue)-1)
    ReportGroupMembershipList = strValue
End Function
 
Function GetManagerDN(Manager)
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    
    strBase = "<LDAP://" & strDNSDomain & ">"
    
    strFilter = "(&(objectCategory=person)(objectClass=user)(cn=*" & Manager & "*))"
    
    strAttributes = "distinguishedName,CN"
    
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    
    Set adoRecordset = CreateObject("ADODB.Recordset")
    adoRecordset.CursorLocation = 3
    adoRecordset.Sort = "distinguishedname"
    adoRecordset.Open strQuery, adoConnection, , , 1
    strresults = ""
    boolResultsFound = False
    Do Until adoRecordset.EOF
        strDN = adoRecordset.Fields("distinguishedName").Value
        sResults = sResults & "(manager=" & strDN & ")"
        boolResultsFound = True
        adoRecordset.MoveNext
    Loop
    if boolResultsFound then
        sResults = "(|" & sResults & ")"
    end if
    GetManagerDN = sResults
End Function
 
Sub FillGroupList
    For Each objOption in lst_groupnames.Options
        objOption.RemoveNode
    Next
 
    For Each objOption in lst_dgnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
    
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(objectCategory=group)"
        strAttributes = "sAMAccountName,primaryGroupToken,distinguishedName,samaccounttype,member"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "distinguishedname"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intNumberOfMembers = 0
            strNTName = adoRecordset.Fields("sAMAccountName").Value
            strPrimary = adoRecordset.Fields("primaryGroupToken").Value
            strdistinguishedName = adoRecordset.Fields("distinguishedName").Value
            strGroupType = GetSAMAccountType(adoRecordset.Fields("samaccounttype").Value)
            if NOT IsNull(adoRecordset.Fields("member").Value) then
                for each strMember in adoRecordset.Fields("member").Value
                    GroupMembershipDB.AddNew
                    GroupMembershipDB("sAMAccountName")          = strNTName
                    GroupMembershipDB("primaryGroupToken")       = strPrimary
                    GroupMembershipDB("distinguishedName")       = strdistinguishedName
                    GroupMembershipDB("samaccounttype")          = strGroupType
                    GroupMembershipDB("MemberDistinguishedName") = strMember
                    GroupMembershipDB.Update
                    intNumberOfMembers = intNumberOfMembers + 1
                next
            else
                GroupMembershipDB.AddNew
                GroupMembershipDB("sAMAccountName")          = strNTName
                GroupMembershipDB("primaryGroupToken")       = strPrimary
                GroupMembershipDB("distinguishedName")       = strdistinguishedName
                GroupMembershipDB("samaccounttype")          = strGroupType
                GroupMembershipDB("MemberDistinguishedName") = ""
                GroupMembershipDB.Update
            End if
            if NOT dicGroupNumbers.Exists(strdistinguishedName) then
                dicGroupNumbers.Add strdistinguishedName, intNumberOfMembers
                if strPrimary = 513 then
                    GetUsersWithPrimaryGroupID 513, strdistinguishedName
                    intNumberOfMembers = dicGroupNumbers.Item(strdistinguishedName)
                end if
            end if
            Select Case adoRecordset.Fields("samaccounttype").Value
                Case 2,268435457,4,536870913,8,268435457
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case -2147483646,268435456,-2147483644,536870912,-2147483640,268435456
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case Else
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
            End Select
            
            adoRecordset.MoveNext
        Loop
    next
    
    span_groupmembership.InnerHTML = "(" & intGroupMembership & ")"
    span_dgmembership.InnerHTML    = "(" & intdgmembership & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Sub FillManagerList
    For Each objOption in lst_managerlist.Options
        objOption.RemoveNode
    Next
    intManagers = 0
    set dicManagerList = CreateObject("Scripting.Dictionary")
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=*))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            strManager = adoRecordset.Fields("manager").Value
            if dicManagerList.Exists(strManager) then
                dicManagerList.Item(strManager) = dicManagerList.Item(strManager) + 1
            else
                dicManagerList.Add strManager, 1
                intManagers = intManagers + 1
            End if
            adoRecordset.MoveNext
        Loop
    next
    for each Manager in dicManagerList
        set newOption = document.createElement("OPTION")
        newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
        newOption.Value = Manager
        lst_managerlist.Add newOption
    next
    span_managerlist.InnerHTML = "(" & intManagers & ")"
End Sub
 
Function GetSubordinateNumbers(manager)
    intSubordinates = 0
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=" & manager & "))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intSubordinates = intSubordinates + 1
            adoRecordset.MoveNext
        Loop
    next
    GetSubordinateNumbers = intSubordinates
End FUnction
 
Function GetSAMAccountType(SAMAccountType)
    Select Case SAMAccountType
        Case 2, 268435457
            GetSAMAccountType = "[GDG]" 'This is a global distribution group
        Case 4, 536870913
            GetSAMAccountType = "[LDG]" 'This is a domain local distribution group
        Case 8, 268435457
            GetSAMAccountType = "[UDG]" 'This is a universal distribution group
        Case -2147483646, 268435456
            GetSAMAccountType = "[GSG]" 'This is a global security group
        Case -2147483644, 536870912
            GetSAMAccountType = "[LSG]" 'This is a domain local security group
        Case -2147483640, 268435456
            GetSAMAccountType = "[USG]" 'This is a universal security group
        Case Else
            GetSAMAccountType = "[Unknown]" 'This is an unknown group type
    End Select
End Function
 
Sub GetUsersWithPrimaryGroupID(PrimaryGroupID,distinguishedName)
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    strSearchField = "(primaryGroupID=" & PrimaryGroupID & ")"
    for each strDomain in arrDomainNames
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
        strAttributes = "cn,primaryGroupID"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 100
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        Set adoRecordset = adoCommand.Execute
        If Not adoRecordset.EOF Then
            Do Until adoRecordset.EOF
                n = n + 1
                adoRecordset.movenext
            Loop
        End If
    next
    dicGroupNumbers.Item(distinguishedName) = n
End Sub
 
Sub FillSubjectList
    For Each objOption in txt_EmailSubject.Options
        objOption.RemoveNode
    Next
    For each strSubjectlineText in arrSubjectText
        set newOption = document.createElement("OPTION")
        newOption.Text = strSubjectlineText
        newOption.Value = strSubjectlineText
        txt_EmailSubject.Add newOption
    Next
End Sub
 
Sub ConvertNamesToEmailAddresses
    txt_EmailToHidden.Value = GetEmailAddresses(txt_EmailTo.Value)
    txt_EmailCCHidden.Value = GetEmailAddresses(txt_EmailCC.Value)
    strEmailTo = txt_EmailToHidden.Value
End Sub
 
Function GetEmailAddresses(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(names,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("mail").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
        end if
    next
    GetEmailAddresses = strValidEmail
End Function
 
Function GetOUPath(OU)
    strOU = ""
    strFQDN = ""
    boolFoundMatch = False
    arrValues = split(OU,",")
    for each strValue in arrValues
        if instr(strValue,"OU=") then
            strOU = strOU & replace(strValue,"OU=","") & "\"
        end if
        if instr(strValue,"DC=") then
            strFQDN = strFQDN & replace(strValue,"DC=","") & "."
        end if
        if instr(strValue,"CN=") then
            if boolFoundMatch then
                strCN = strCN & replace(strValue,"CN=","") & "\"
            else
                'Skip the first match - this is always the user name
                boolFoundMatch = True
            end if
        end if
    next
    if strFQDN <> "" then
        strFQDN = left(strFQDN,len(strFQDN)-1)
        if strOU <> "" then
            strOU = left(strOU,len(strOU)-1)
        else
            'strOU = "{object not found in any OU}"
            if strCN <> "" then
                strOU = left(strCN,len(strCN)-1)
            end if
        end if
        GetOUPath = (Split(strOU,"\")(0))
    else
        GetOUPath = ""
    end if
End Function
 
Function GetComputerInfo(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidComputer = ""
 
    strResolve = trim(names)
 
    if strResolve <> "" then
        Set objRoot = GetObject("LDAP://rootDSE")
        strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
        Set objConnection = CreateObject("ADODB.Connection")
        Set objCommand = CreateObject("ADODB.Command")
 
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open "Active Directory Provider"
 
        Set objCommand.ActiveConnection = objConnection
        objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _
        "(cn=" & strResolve & "));cn,samAccountName,distinguishedName,operatingsystem,operatingsystemservicepack,whencreated,description;subtree"
 
        objCommand.Properties("Page Size") = 1000
        objCommand.Properties("Timeout") = 90
        objCommand.Properties("Cache Results") = False
    
        Set objRecordSet1 = objCommand.Execute
 
        While Not objRecordSet1.EOF
 
            if IsNull(objRecordSet1.Fields("distinguishedName").Value) then
                sDN = ""
            else
                sDN = replace(objRecordSet1.Fields("distinguishedName").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystem").Value) then
                sOS = ""
            else
                sOS = replace(objRecordSet1.Fields("operatingsystem").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystemservicepack").Value) then
                sSP = ""
            else
                sSP = replace(objRecordSet1.Fields("operatingsystemservicepack").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("whencreated").Value) then
                sWC = ""
            else
                sWC = replace(objRecordSet1.Fields("whencreated").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("description").Value) then
                sDS = ""
            else
                sDS = join(objRecordSet1.Fields("description").Value)
                sDS = replace(sDS,vbCRLF,"")
            End if
 
            strValidComputer = Array("""" & sDN & """","""" & sOS & """","""" & sSP & """","""" & sWC & """","""" & sDS & """")
            objRecordSet1.MoveNext
        Wend 
    end if
 
    if isArray(strValidComputer) then
        GetComputerInfo = strValidComputer
    else
        GetComputerInfo = ""
    end if
End Function
 
Sub ShowSubMenu(Parent,Child)
    If Child.style.display="block" Then
        Parent.classname="Menuover"
        Child.style.display="none"
        Set LastChildMenu=Nothing
    Else
        Parent.classname="Menuin"
        Child.style.display="block"
        Set LastChildMenu=Child
    End If
    Set LastMenu=Parent
End Sub
 
Sub MenuOver(Parent,Child)
    If LastChildMenu is Nothing Then
        Parent.className="MenuOver"
    Else
        If LastMenu is Parent Then
            Parent.className="MenuIn"
        Else
            HideMenu
            ShowSubMenu Parent,Child
        End If
    End If
End Sub
 
Sub MenuOut(Menu)
    If LastChildMenu is Nothing Then Menu.className="MenuOut"
End Sub
 
Sub HideMenu
    If Not LastChildMenu is Nothing Then
        LastChildMenu.style.display="none"
        Set LastChildMenu=Nothing
        LastMenu.classname="Menuout"
    End If
End Sub
 
Sub SubMenuOver(Menu)
    Menu.className="SubMenuOver"
End Sub
 
Sub SubMenuOut(Menu)
    Menu.className="SubMenuOut"
End Sub
 
Sub SaveAs
    on error resume next
    Dim oDLG
    Set oDLG=CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to save.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            Save
        End If
    else
        With oDLG
            .DialogTitle = "Save As"
            .Filter="Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .ShowSave
            If .FileName <> "" Then
                FileName = .FileName
                Save
            End If
        End With
    end if
    Set oDLG=Nothing
    DisplayTitle
End Sub
 
Sub Save()
    Dim fso,f
    If FileName <> "" Then
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f = fso.CreateTextFile(FileName,True)
        
        'This is the text to get saved into the file
        with f
            .writeline "<root>"
            .writeline "<searchfield>" & globalStrSearchField & "</searchfield>"
            .writeline "<btnpush>" & globalStrSearchBtnPush & "</btnpush>"
            .writeline "<to>" & txt_EmailTo.value & "</to>"
            .writeline "<cc>" & txt_EmailCC.value & "</cc>"
            .writeline "<bcc>" & strEmailBCC & "</bcc>"
            .writeline "<subject>" & txt_EmailSubject.value & "</subject>"
            .writeline "<emailbody>" & txt_EmailBody.value & "</emailbody>"
            if chk_selectall.Checked then .writeline "<checkboxes>chk_selectall</checkboxes>"
            if chk_seatno.Checked then .writeline "<checkboxes>chk_seatno</checkboxes>"
            if chk_building.Checked then .writeline "<checkboxes>chk_building</checkboxes>"
            if chk_extensionno.Checked then .writeline "<checkboxes>chk_extensionno</checkboxes>"
            if chk_empid.Checked then .writeline "<checkboxes>chk_empid</checkboxes>"
            if chk_department.Checked then .writeline "<checkboxes>chk_department</checkboxes>"
            if chk_designation.Checked then  .writeline "<checkboxes>chk_designation</checkboxes>"
            if chk_name.Checked then .writeline "<checkboxes>chk_name</checkboxes>"
            if chk_loginname.Checked then .writeline "<checkboxes>chk_loginname</checkboxes>"
            if chk_email.Checked then .writeline "<checkboxes>chk_email</checkboxes>"
            if chk_mailboxsize.Checked then .writeline "<checkboxes>chk_mailboxsize</checkboxes>"
            if chk_mailboxstore.Checked then .writeline "<checkboxes>chk_mailboxstore</checkboxes>"
            if chk_notes.Checked then .writeline "<checkboxes>chk_notes</checkboxes>"
            if chk_computerserialno.Checked then .writeline "<checkboxes>chk_computerserialno</checkboxes>"
            if chk_replacedmachine.Checked then .writeline "<checkboxes>chk_replacedmachine</checkboxes>"
            if chk_replacedcomputerserialno.Checked then .writeline "<checkboxes>chk_replacedcomputerserialno</checkboxes>"
            if chk_oupathcomputer.Checked then .writeline "<checkboxes>chk_oupathcomputer</checkboxes>"
            if chk_computeros.Checked then .writeline "<checkboxes>chk_computeros</checkboxes>"
            if chk_computerdescription.Checked then .writeline "<checkboxes>chk_computerdescription</checkboxes>"
            if chk_computercreated.Checked then  .writeline "<checkboxes>chk_computercreated</checkboxes>"
            if chk_mobileno.Checked then  .writeline "<checkboxes>chk_mobileno</checkboxes>"
            if chk_company.Checked then .writeline "<checkboxes>chk_company</checkboxes>"
            if chk_address.Checked then  .writeline "<checkboxes>chk_address</checkboxes>"
            if chk_city.Checked then .writeline "<checkboxes>chk_city</checkboxes>"
            if chk_state.Checked then .writeline "<checkboxes>chk_state</checkboxes>"
            if chk_zipcode.Checked then .writeline "<checkboxes>chk_zipcode</checkboxes>"
            if chk_country.Checked then .writeline "<checkboxes>chk_country</checkboxes>"
            if chk_homephone.Checked then .writeline "<checkboxes>chk_homephone</checkboxes>"
            if chk_manager.Checked then .writeline "<checkboxes>chk_manager</checkboxes>"
            if chk_whencreated.Checked then .writeline "<checkboxes>chk_whencreated</checkboxes>"
            if chk_oupathuser.Checked then .writeline "<checkboxes>chk_oupathuser</checkboxes>"
            if chk_lastlogintimestamp.Checked then .writeline "<checkboxes>chk_lastlogintimestamp</checkboxes>"
            if chk_groupmembership.Checked then .writeline "<checkboxes>chk_groupmembership</checkboxes>"
            if chk_dgmembership.Checked then .writeline "<checkboxes>chk_dgmembership</checkboxes>"
            if chk_managerlist.Checked then .writeline "<checkboxes>chk_managerlist</checkboxes>"
            if chk_subordinates.Checked then .writeline "<checkboxes>chk_subordinates</checkboxes>"
            .writeline "</root>"
            .Close
        end with
        
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        XmlDom.async = False
        XmlDom.Load(FileName)
        xmlDom.Save(FileName)
        
        Set f = Nothing
        Set fso = Nothing
    Else
        SaveAs
    End If
End Sub
 
Sub OpenIt
    UnCheckAllBoxes
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    xmlDom.load(FileName)
    
    globalStrSearchField = xmlDom.getElementsByTagName("searchfield").item(0).text
    globalStrSearchBtnPush = xmlDom.getElementsByTagName("btnpush").item(0).text
    txt_EmailTo.value = xmlDom.getElementsByTagName("to").item(0).text
    txt_EmailCC.value = xmlDom.getElementsByTagName("cc").item(0).text
    strEmailBCC = xmlDom.getElementsByTagName("bcc").item(0).text
    txt_EmailSubject.value = xmlDom.getElementsByTagName("subject").item(0).text
    txt_EmailBody.value = xmlDom.getElementsByTagName("emailbody").item(0).text
    
    for n = 0 to xmlDom.getElementsByTagName("checkboxes").Length-1
        execute(xmlDom.getElementsByTagName("checkboxes").item(n).text & ".checked = True")
    next
    
    DisplayTitle
    
    Submit_Form "FileOpen"
End Sub
 
Sub Open()
    on error resume next
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            OpenIt
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                FileName = .FileName
                OpenIt
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub DisplayTitle
    If FileName="" Then
        document.Title="Default - " & oHTA.ApplicationName
    Else
        document.Title=FileName & " - " & oHTA.ApplicationName
    End If
End Sub
 
Sub ClickTheSpecialReportButton
    Submit_Form("Disabled")
End Sub
 
Sub SpecialReportNewUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("Main")
End Sub
 
Sub SpecialReportDisabledUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub SpecialReportDisabledUsersSomeDay
    Clear_Form ""
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    txt_whencreated.value = sRtn
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub GetChkProfiles 
    For Each objOption in lst_ChkProfiles.Options
        objOption.RemoveNode
    Next
    
    strAnswer = fAppData & "\profile.xml"
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If NOT objFSO.FileExists(strAnswer) Then
        'Create profile.xml
	Set f = objFSO.CreateTextFile(strAnswer,True)
        with f
            .writeline "<root>"
            .writeline "<profile val=""Default"">"
            .writeline "<checkboxes val=""chk_selectall"" />"
            .writeline "<checkboxes val=""chk_seatno"" />"
            .writeline "<checkboxes val=""chk_replacementseatno"" />"
            .writeline "<checkboxes val=""chk_building"" />"
            .writeline "<checkboxes val=""chk_extensionno"" />"
            .writeline "<checkboxes val=""chk_empid"" />"
            .writeline "<checkboxes val=""chk_department"" />"
            .writeline "<checkboxes val=""chk_designation"" />"
            .writeline "<checkboxes val=""chk_name"" />"
            .writeline "<checkboxes val=""chk_loginname"" />"
            .writeline "<checkboxes val=""chk_email"" />"
            .writeline "<checkboxes val=""chk_mailboxsize"" />"
            .writeline "<checkboxes val=""chk_mailboxstore"" />"
            .writeline "<checkboxes val=""chk_notes"" />"
            .writeline "<checkboxes val=""chk_computerserialno"" />"
            .writeline "<checkboxes val=""chk_replacedmachine"" />"
            .writeline "<checkboxes val=""chk_replacedcomputerserialno"" />"
            .writeline "<checkboxes val=""chk_oupathcomputer"" />"
            .writeline "<checkboxes val=""chk_computeros"" />"
            .writeline "<checkboxes val=""chk_computerdescription"" />"
            .writeline "<checkboxes val=""chk_computercreated"" />"
            .writeline "<checkboxes val=""chk_mobileno"" />"
            .writeline "<checkboxes val=""chk_company"" />"
            .writeline "<checkboxes val=""chk_address"" />"
            .writeline "<checkboxes val=""chk_city"" />"
            .writeline "<checkboxes val=""chk_state"" />"
            .writeline "<checkboxes val=""chk_zipcode"" />"
            .writeline "<checkboxes val=""chk_country"" />"
            .writeline "<checkboxes val=""chk_homephone"" />"
            .writeline "<checkboxes val=""chk_manager"" />"
            .writeline "<checkboxes val=""chk_whencreated"" />"
            .writeline "<checkboxes val=""chk_oupathuser"" />"
            .writeline "<checkboxes val=""chk_lastlogintimestamp"" />"
            .writeline "<checkboxes val=""chk_groupmembership"" />"
            .writeline "<checkboxes val=""chk_dgmembership"" />"
            .writeline "<checkboxes val=""chk_managerlist"" />"
            .writeline "<checkboxes val=""chk_subordinates"" />"
            .writeline "</profile>"
            .writeline "</root>"
            .Close
	end with
 
	Set xmlDom = CreateObject("Microsoft.XMLDOM")
	XmlDom.async = False
	XmlDom.Load(strAnswer)
	xmlDom.Save(strAnswer)
    End If
 
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile")
    
    for n = 0 to oNodes.length - 1
        set newOption = document.createElement("OPTION")
        newOption.Text = oNodes(n).selectSingleNode("@val").Text
        newOption.Value = oNodes(n).selectSingleNode("@val").Text
        lst_ChkProfiles.Add newOption
    next
 
    Set f = Nothing
    Set objFSO = Nothing
End Sub
 
Sub lst_chkprofiles_OnChange
 
    UnCheckAllBoxes
 
    strAnswer = fAppData & "\profile.xml"
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]/checkboxes")   
 
    For i = 0 To oNodes.length - 1
        execute(oNodes(i).selectSingleNode("@val").Text & ".Checked = True")
    Next
 
    TestToSeeWhatLinesAreHidden
End Sub
 
Sub DeleteFromCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        For Each objOption in lst_chkprofiles.Options
            If objOption.Value = lst_chkprofiles.Value Then
                objOption.RemoveNode
            End If
        Next
        msgbox "Checkbox profile deleted."
        lst_chkprofiles_OnChange
    else
        msgbox "You cannot delete the default profile."
    end if
End Sub
 
Sub ModifyCurrentCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        strProfileName = lst_chkprofiles.Value
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        
        Const ForReading = 1
        Const ForWriting = 2
     
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
     
        Do Until objFile.AtEndOfStream
            strLine = objFile.Readline
            strLine = Trim(strLine)
            If strLine <> "</root>" Then
                strContents = strContents & strLine & vbCrLf
            End If
        Loop
     
        objFile.Close
        
        Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
        
        with f
            .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
            if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
            if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
            if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
            if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
            if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
            if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
            if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
            if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
            if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
            if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
            if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
            if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
            if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
            if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
            if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
            if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
            if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
            if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
            if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
            if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
            if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
            if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
            if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
            if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
            if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
            if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
            if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
            if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
            if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
            if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
            if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
            if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
            if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
            if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
            if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
            if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
            if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
            .writeline vbTab & "</profile>"
            .writeline "</root>"
            .close
        end with
        
        msgbox "Checkbox profile modified."
    else
        msgbox "You cannot modify the default profile."
    end if
End Sub
 
Sub AddToCheckboxProfile
    strProfileName = window.prompt("Please enter a profile name.", "My profile name")
    strAnswer = fAppData & "\profile.xml"
 
    Const ForReading = 1
    Const ForWriting = 2
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
 
    Do Until objFile.AtEndOfStream
        strLine = objFile.Readline
        strLine = Trim(strLine)
        If strLine <> "</root>" Then
            strContents = strContents & strLine & vbCrLf
        End If
    Loop
 
    objFile.Close
    
    Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
    
    with f
        .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
	if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
	if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
        if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
	if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
	if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
	if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
	if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
	if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
	if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
	if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
	if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
	if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
	if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
	if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
	if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
	if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
	if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
	if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
	if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
	if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
	if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
	if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
	if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
	if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
	if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
	if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
	if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
	if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
	if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
	if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
	if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
	if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
	if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
	if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
	if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
	if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
	if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
	.writeline vbTab & "</profile>"
	.writeline "</root>"
        .close
    end with
 
    set newOption = document.createElement("OPTION")
    newOption.Text = strProfileName
    newOption.Value = strProfileName
    lst_ChkProfiles.Add newOption
 
    lst_ChkProfiles.Value = strProfileName
End Sub
 
Sub AddToQueryBuilder
	globalstrQueryBuilder = globalstrQueryBuilder & globalstrSearchField
	if NOT chk_qbrecorder.Checked then
		msgbox "The query has been added."
	end if
End Sub
 
Sub QueryBuilderRecorder
    if chk_qbrecorder.Checked then
        msgbox "Query Builder is now recording."
    else
        msgbox "Query Builder has stopped recording." & vbCrLf & "Click OK to view the combined query."
        RunQueryBuilder
    end if
End Sub
 
Sub ViewQueryBuilder
    if globalstrQueryBuilder <> "" then
        msgbox "(|" & globalstrQueryBuilder & ")"
    else
        msgbox "There are no stored queries to view."
    end if
End Sub
 
Sub RunQueryBuilder
    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
    globalstrSearchBtnPush = "FileOpen"
    Submit_Form "FileOpen"
End Sub
 
Sub ClearQueryBuilder
    globalstrQueryBuilder = ""
End Sub
 
Sub txt_EmailSubject_OnChange
    For i = 0 to (txt_EmailSubject.Options.Length - 1)
        If (txt_EmailSubject.Options(i).Selected) Then
            strEmailTo = arrToSpecial(i)
            strEmailCC = arrCCSpecial(i)
            txt_EmailTo.Value = strEmailTo
            txt_EmailCC.Value = strEmailCC
        End If
    Next
End Sub
 
Sub PingComputer(name)
    if name <> "" then
        strComuptername = trim(name)
        'Run PING command
        Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
        'Take ping reults and put into variable strPingResult 
        strPingResult = 0
        For Each oPingResult In objPingResults
            strPingResult = oPingResult.ResponseTime
            strIPAddress  = oPingResult.ProtocolAddress
        Next
        'Catch PINGS that do not have a result - typically this is for unreachable devices
        if IsEmpty(strPingResult) then
            strPingResult = 9999
        end if
        if IsNULL(strPingResult) then
            strPingResult = 9999
        end if
        ' Run ping again if first attempt fails
        if strPingResult = 9999 then
            'Run PING command
            Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
            'Take ping reults and put into variable strPingResult 
            strPingResult = 0
            For Each oPingResult In objPingResults
                strPingResult = oPingResult.ResponseTime
                strIPAddress  = oPingResult.ProtocolAddress
            Next
            'Catch PINGS that do not have a result - typically this is for unreachable devices
            if IsEmpty(strPingResult) then
                strPingResult = 9999
            end if
            if IsNULL(strPingResult) then
                strPingResult = 9999
            end if
        end if
        span_computerip.innerhtml = strIPAddress
        if strPingResult = 9999 then
            span_computeronline.innerhtml = "Offline"
        else
            span_computeronline.innerhtml = "Online"
        end if
    else
        span_computerip.innerhtml = " "
        span_computeronline.innerhtml = " "
    end if
End Sub
 
Sub bt2Go_onclick()
 
    '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, DENY, POS, NEG
    Dim objNetwork, objShell
 
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Write username for the user that needs to be enabled or disabled:'
    USR = InputBox("Username:", "Enable or Disable Active Directory User", _
    "Write Username Here")
     
    if USR = "" then
	exit sub
    End if
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** Declare NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate name into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
    '** Do LDAP bind to object:'
    Set objUser = GetObject("LDAP://" & strUserDN)
     
    '** Get full name:'
    strUS1 = Mid(strUserDN,4)
    strUS2 = Split(strUS1, ",")
    For i = LBound(strUS2) to UBound(strUS2)
        strNM = strUS2(i)
        Exit For
    Next
 
    '** If no error, enable or disable user:'
    If Err = 0 Then
        Const ADS_UF_ACCOUNTDISABLE = 2
        intUAC = objUser.Get("userAccountControl")
        objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
        objUser.SetInfo
        If intUAC AND ADS_UF_ACCOUNTDISABLE Then
            POS = 1
        Else
            NEG = 1
        End If
    Else
        objShell.Popup UCase(USR) & " was not found. Please try again.", _
        5, "Unknown Username", 48
        exit sub
    End If
 
    '** If no permission, give message:'
    If Err = "-2147024891" Then
        DENY = 1
        objShell.Popup "You can not enable or disable this user.", _
        5, "Permission Denied", 48
        exit sub
    End If
 
    '** If no error, show result:'
    If DENY <> 1 Then
        If POS = 1 Then
            MsgBox UCase(USR) & " were successfully enabled.", _
            64, "User enabled by " & strNM2
        End If
 
        If NEG = 1 Then
            MsgBox UCase(USR) & " were successfully disabled.", _
            64, "User disabled by " & strNM2
        End If
    End If
End Sub
 
Sub bt1Go_onclick()
     '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, EROR, ABS
    Dim objNetwork, objShell, objFSO
     
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Type username for the user that needs password change:'
    USR = InputBox("Username:", "Create Temporary Active Directory User Password", _
    "Write Username Here")
     
    if USR = "" then
        exit sub
    End if
 
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate username into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    If Err <> 0 Then
        ABS = 1
    End If
     
    '** Execute if object is found:'
    If ABS <> 1 Then
        strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
        '** Do LDAP bind to object:'
        Set objUser = GetObject("LDAP://" & strUserDN)
     
        '** Get full name:'
        strUS1 = Mid(strUserDN,4)
        strUS2 = Split(strUS1, ",")
        For i = LBound(strUS2) to UBound(strUS2)
            strNM = strUS2(i)
            Exit For
        Next
     
        '** Assign password and parameters:'
        If strNM <> "" Then
            TNP = "changeme" & Mid(objFSO.GetTempName,4,4)
            objUser.SetPassword TNP
            If Err <> 0 Then
                EROR = 1
            End If
            objUser.Put "pwdLastSet", 0
            objUser.IsAccountLocked = False
            objUser.SetInfo
        End If
     
        '** If no error, show new temporary password:'
        If EROR <> 1 Then
            MsgBox "New temporary password for " & UCase(USR) & " (" & strNM & "):" & _
            vbCrLf & vbCrLf & TNP & vbCrLf, 64, "New Password, configured by " & strNM2
        End If
 
    End If
 
    '** End if object not found:'
    If ABS = 1 Then
        MsgBox UCase(USR) & " was not found. Please try again.", _
        48, "Unknown Username"
    End If
 
    '** If no permission, give message:'
    If EROR = 1 Then
        MsgBox "You can not change password for this user.", _
        48, "Permission Denied"
    End If
 
End Sub 
 
Sub ImportFromExcel
    on error resume next
    boolEndofFile = False
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "D:\your-spreadsheet.xls")
        if oDLG <> "" then
            globalstrQueryBuilder = ""
            Set objExcel = CreateObject("Excel.Application")
            Set objWorkbook = objExcel.Workbooks.Open(oDLG)
            intRow = 2
            Do Until boolEndofFile
                'According to ticket Q__23804616, these are the fields that are in the spreadsheet;
                'Emp ID,Seat No,Email ID,Full Name, NT Login,Machine Name
                strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                    boolEndofFile = True
                else
                    if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                    if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                    if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                    if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                    if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                    if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                end if
                intRow = intRow + 1
            Loop
            objExcel.Quit
            globalstrQueryBuilder = strValue
	    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	    globalstrSearchBtnPush = "FileOpen"
	    Submit_Form "FileOpen"
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Excel Workbook|*.xls"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                globalstrQueryBuilder = ""
                Set objExcel = CreateObject("Excel.Application")
                Set objWorkbook = objExcel.Workbooks.Open(.FileName)
                intRow = 2
                Do Until boolEndofFile
                    strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                    strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                    strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                    strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                    strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                    strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                    if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                        boolEndofFile = True
                    else
                        if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                        if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                        if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                        if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                        if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                        if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                    end if
                    intRow = intRow + 1
                Loop
                objExcel.Quit
                globalstrQueryBuilder = strValue
	        globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	        globalstrSearchBtnPush = "FileOpen"
	        Submit_Form "FileOpen"
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub About_OnClick
    'Enter names as contibuters increase.
    msgbox vbCRLF & "User and Computer Account Control" & vbCRLF & vbCRLF & "Written for Sharatha and contributed by;" & vbCRLF & vbCRLF & vbtab & _
    """rejoinder""" & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab
End Sub
 
Sub RunHTA(NameOfHTA)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run NameOfHTA
End Sub
 
Sub allowpings
    if chk_allowpings.Checked then
        boolAllowPing = True
    else
        boolAllowPing = False
    end if
End Sub
 
Sub LookupLastLogin
    if chk_LookupLastLogin.Checked then
        boolLookupLastLogin = True
    else
        boolLookupLastLogin = False
    end if
End Sub
 
Sub TableReports
    if chk_TableReports.Checked then
        boolTableReports = True
    else
        boolTableReports = False
    end if
End Sub
 
Sub GetMailboxDetails
    on error resume next
    strExchangeServerQuery = "winmgmts://" & strEmailServer & "/root/cimv2/applications/exchange"
    set serverList = GetObject(strExchangeServerQuery).InstancesOf("ExchangeServerState")
    For each ExchangeServer in serverList
        strExchangeQuery = "winmgmts://" & ExchangeServer.Name & "/root/MicrosoftExchangeV2"
        strExchangeQuery = "winmgmts://" & strEmailServer & "/root/MicrosoftExchangeV2"
        Set objMailboxes = GetObject(strExchangeQuery).InstancesOf("Exchange_Mailbox")
        For each mailbox in objMailboxes
            MailboxList.AddNew
            MailboxList("legacyExchangeDN") = mailbox.LegacyDN
            MailboxList("mailboxsize") = Round(mailbox.Size / 1024)
            MailboxList.Update
        Next
    Next
    MailboxList.MoveFirst
End Sub
 
Sub MailboxSizeCompare
    oDLG = window.prompt("Enter the mailbox size limit in MB.", "1000")
    if IsNumeric(oDLG) then
        Submit_Form("MailboxSize:" & oDLG)
    end if
End Sub
 
Sub DoCal(elTarget)
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    Execute(elTarget & ".value = sRtn")
    Detect_Search_Field(elTarget)
End Sub
 
Function GetOUMembers(OU)
    strValue = ""
    on error resume next
    GroupMembershipDB.Filter = "MemberDistinguishedName LIKE '*OU=" & OU & "*'"
    GroupMembershipDB.Sort   = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    Do While Not GroupMembershipDB.EOF
        strValue = strValue & "(DistinguishedName=" & GroupMembershipDB.Fields.Item("MemberDistinguishedName").Value & ")"
        GroupMembershipDB.MoveNext
    Loop
    if err.number > 0 then
        GetOUMembers = "INVALID"
    else
        GetOUMembers = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForOSQuery(OS)
    strValue = ""
    strSearchField = "(operatingsystem=*" & OS & "*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForOSQuery = "INVALID"
    else
        GetComputersForOSQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForDateCreatedQuery(CreatedDate)
    strValue = ""
    strWhenCreated = Year(CreatedDate) & Right("0" & Month(CreatedDate), 2) & Right("0" & Day(CreatedDate), 2)
    strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForDateCreatedQuery = "INVALID"
    else
        GetComputersForDateCreatedQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersBasedOnOU(OU)
    strValue = ""
    
    strSearchField = "(distinguishedName=*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
            
    boolFoundRecords = False
            
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
                  
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
 
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,distinguishedName"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
 
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
                  
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                if InStr(adoRecordset.Fields("distinguishedName").Value,OU) > 0 then
                    strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                End if
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersBasedOnOU = "INVALID"
    else
        GetComputersBasedOnOU = "(|" & strValue & ")"
    End if
End Function
 
</script>
 
<STYLE TYPE="text/css">
<!--
body		{background-color: menu;color: menutext;}
td		{font-family: MS Sans Serif;font-size: 8pt;}
input		{font-family: MS Sans Serif;font-size: 8pt;}
button		{font-family: MS Sans Serif;font-size: 8pt;}
option		{font-family: MS Sans Serif;font-size: 8pt;}
select		{font-family: MS Sans Serif;font-size: 8pt;}
.submenu	{position:absolute;top=35;
		background-color:Menu;
		border="1px outset";}
.MenuIn		{border:"1px inset";cursor:default;}
.Menuover	{border:"1px outset";cursor:default;}
.Menuout	{}
.Submenuover	{background-color:highlight;color:highlighttext;cursor:default;}
.Submenuout	{background-color:Menu;color:MenuText;cursor:default;}
.HideFromGUI	{display:none;}
 
-->
</STYLE>
<body>
<!-- Main menu -->
<TABLE id=MenuTable height=25><TR>
	<TD	onclick='ShowSubMenu Me,MyFileMenu'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> Query </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,MyEditMenu'
		onmouseover='MenuOver Me,MyEditMenu'
		onmouseout='MenuOut Me'> Reports </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,QueryBuilderMenu'
		onmouseover='MenuOver Me,QueryBuilderMenu'
		onmouseout='MenuOut Me'> Query&nbsp;Builder </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,ToolsMenu'
		onmouseover='MenuOver Me,ToolsMenu'
		onmouseout='MenuOut Me'> Tools </TD>
	<TD	>|</TD>
	<TD	> Checkbox&nbsp;Profile&nbsp;<select id="lst_chkprofiles" name="lst_chkprofiles">
 
	</select>
	</TD>
<!-- Main menu, Checkbox profile tools -->
	<TD	onclick='AddToCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [+]Add</TD>
	<TD	onclick='DeleteFromCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [-]Delete</TD>
	<TD	onclick='ModifyCurrentCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [!]Modify</TD>
	<TD	>|</TD>
	<TD	onclick='About_OnClick'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> About</TD>
	<TD	>|</TD>
	<TD onclick="HideMenu" width="100%" border="2"></TD>
	</TR></TABLE>
<!-- Drop down for QUery -->
<TABLE ID=MyFileMenu class=submenu style="left=10;display:none;">
        <TR><TD	onclick="HideMenu:open"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Open</TD></TR>
        <TR><TD onclick="HideMenu:importfromexcel"
                onmouseover='Submenuover Me'
                onmouseout='Submenuout Me'> Import from Excel</TD></TR>
	<TR><TD	onclick="HideMenu:save"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save</TD></TR>
	<TR><TD	onclick="HideMenu:saveAs"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save As</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:window.close"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Quit</TD></TR>
</TABLE>
<!-- Drop down for Reports -->
<TABLE ID=MyEditMenu class=submenu style="left=50;display:none;">
        <TR><TD	onclick="HideMenu:Email_This_Record"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email This Record</TD></TR>
	<TR><TD	onclick="HideMenu:Email_All_Records"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email All Records</TD></TR>
	<TR><TD	onclick="HideMenu:Email_As_Attachment"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email as Attachment</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:RunScript"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save to</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:ClickTheSpecialReportButton"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> All Disabled Users</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified Today</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersSomeDay"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified...</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportNewUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> New Users Created Today</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:7')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 week</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:30')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 month</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:60')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 2 months</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:MailboxSizeCompare"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Users with mailbox size over...</TD></TR>
</TABLE>
<!-- Drop down for Query Builder -->
<TABLE ID=QueryBuilderMenu class=submenu style="left=97;display:none;">
        <TR><TD	onclick="HideMenu:AddToQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Add recent query to Query Builder</TD></TR>
        <TR><TD	onclick="HideMenu:QueryBuilderRecorder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Query Builder Recorder<input type="checkbox" id="chk_qbrecorder" name="chk_qbrecorder"></TD></TR>
	<TR><TD	onclick="HideMenu:ViewQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> View Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:RunQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Run Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:ClearQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Clear Query Builder</TD></TR>
</TABLE>
<!-- Drop down for Tools -->
<TABLE ID=ToolsMenu class=submenu style="left=170;display:none;">
        <TR><TD	onclick="HideMenu:allowpings"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Allow Pings<input type="checkbox" id="chk_allowpings" name="chk_allowpings"></TD></TR>
        <TR><TD	onclick="HideMenu:LookupLastLogin"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Look up last login<input type="checkbox" id="chk_LookupLastLogin" name="chk_LookupLastLogin"></TD></TR>
        <TR><TD	onclick="HideMenu:tablereports"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Invert emails to table format<input type="checkbox" id="chk_tablereports" name="chk_tablereports"></TD></TR>
	<TR><TD><HR></TD></TR>
        <TR><TD	onclick="HideMenu:RunHTA('HTA1.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 1</TD></TR>
	<TR><TD	onclick="HideMenu:RunHTA('HTA2.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 2</TD></TR>
</TABLE>
<hr>
 <table width="100%" border="0" onclick="HideMenu">
            <tr>
                  <td align="left" colspan="2" valign="top">
                        <table border="0" padding="1">
                              <tr>
                                    <td>
                                         <fieldset>
                                         <LEGEND>Email Settings</LEGEND>
                                         <table border="0">
                                         <tr><td>To:</td><td><button onclick="ShowDialogTo">Resolve</button></td><td><input type="text" id="txt_EmailTo" name="txt_EmailTo" size="50"><input type="hidden" id="txt_EmailToHidden" name="txt_EmailToHidden" size="50"><br></td></td><td rowspan="4" valign="top">Email&nbsp;Body:</td><td rowspan="3" valign="top"><textarea id="txt_EmailBody" name="txt_EmailBody" rows=5 cols=40></TEXTAREA></td></tr>
                                         <tr><td>CC:</td><td><button onclick="ShowDialogCC">Resolve</button></td><td><input type="text" id="txt_EmailCC" name="txt_EmailCC" size="50"><input type="hidden" id="txt_EmailCCHidden" name="txt_EmailCCHidden" size="50"><br></td></tr>
                                         <tr><td>Email Subject:</td><td></td><td><select id="txt_EmailSubject" name="txt_EmailSubject"></select></td></tr>
                                         </table>
                                         </fieldset>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
            <tr>
                  <td align="left" valign="top" width="38%">
                        <table border="0">
                              <tr>
                                    <td>
                                          &nbsp;
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_selectall" name="chk_selectall" checked=True onclick="vbs:SelectAllCheck">Select/Deselect All
                                    </td>
                              </tr>
                              <tr id=tr_seatno>
                                    <td>
                                          Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_seatno" name="chk_seatno" checked=True><input type="text" size="40" id="txt_seatno" name="txt_seatno" onkeypress="vbs:Detect_Search_Field('txt_seatno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacementseatno>
                                    <td>
                                          Replacement Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacementseatno" name="chk_replacementseatno" checked=True><input type="text" size="40" id="txt_replacementseatno" name="txt_replacementseatno">
                                    </td>
                              </tr>
                              <tr id=tr_building>
                                    <td>
                                          Building:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_building" name="chk_building" checked=True><input type="text" size="40" id="txt_building" name="txt_building" onkeypress="vbs:Detect_Search_Field('txt_building')">
                                    </td>
                              </tr>
                              <tr id=tr_extensionno>
                                    <td>
                                          Extension No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_extensionno" name="chk_extensionno" checked=True><input type="text" size="40" id="txt_extensionno" name="txt_extensionno" onkeypress="vbs:Detect_Search_Field('txt_extensionno')">
                                    </td>
                              </tr>
                              <tr id=tr_empid>
                                    <td>
                                          Emp ID:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_empid" name="chk_empid" checked=True><input type="text" size="10" id="txt_empid" name="txt_empid" onkeypress="vbs:Detect_Search_Field('txt_empid')">
                                    </td>
                              </tr>
                              <tr id=tr_department>
                                    <td>
                                          Department:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_department" name="chk_department" checked=True><input type="text" size="50" id="txt_department" name="txt_department" onkeypress="vbs:Detect_Search_Field('txt_department')">
                                    </td>
                              </tr>
                              <tr id=tr_designation>
                                    <td>
                                          Designation:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_designation" name="chk_designation" checked=True><input type="text" size="50" id="txt_designation" name="txt_designation" onkeypress="vbs:Detect_Search_Field('txt_designation')">
                                    </td>
                              </tr>
                              <tr id=tr_name>
                                    <td>
                                          User Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_name" name="chk_name" checked=True><input type="text" size="40" id="txt_name" name="txt_name" onkeypress="vbs:Detect_Search_Field('txt_name')">
<span id="span_userorcontact">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_loginname>
                                    <td>
                                          Login Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_loginname" name="chk_loginname" checked=True><input type="text" size="40" id="txt_loginname" name="txt_loginname" onkeypress="vbs:Detect_Search_Field('txt_loginname')"> 
<span id="span_enabled">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_email>
                                    <td>
                                          Email Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_email" name="chk_email" checked=True><input type="text" size="50" id="txt_email" name="txt_email" onkeypress="vbs:Detect_Search_Field('txt_email')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxsize>
                                    <td>
                                          Mailbox Size (MB):
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxsize" name="chk_mailboxsize" checked=True><input type="text" size="20" id="txt_mailboxsize" name="txt_mailboxsize" onkeypress="vbs:Detect_Search_Field('txt_mailboxsize')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxstore>
                                    <td>
                                          Mailbox Store:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxstore" name="chk_mailboxstore" checked=True><input type="text" size="50" id="txt_mailboxstore" name="txt_mailboxstore" onkeypress="vbs:Detect_Search_Field('txt_mailboxstore')">
                                    </td>
                              </tr>
                              <tr id=tr_mobileno>
                                    <td>
                                          Mobile Number:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mobileno" name="chk_mobileno" checked=True><input type="text" size="20" id="txt_mobileno" name="txt_mobileno" onkeypress="vbs:Detect_Search_Field('txt_mobileno')">
                                    </td>
                              </tr>
                              <tr id=tr_company>
                                    <td>
                                          Company:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_company" name="chk_company" checked=True><input type="text" size="20" id="txt_company" name="txt_company" onkeypress="vbs:Detect_Search_Field('txt_company')">
                                    </td>
                              </tr>
                              <tr id=tr_address>
                                    <td>
                                          Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_address" name="chk_address" checked=True><input type="text" size="20" id="txt_address" name="txt_address" onkeypress="vbs:Detect_Search_Field('txt_address')">
                                    </td>
                              </tr>
                              <tr id=tr_city>
                                    <td>
                                          City:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_city" name="chk_city" checked=True><input type="text" size="20" id="txt_city" name="txt_city" onkeypress="vbs:Detect_Search_Field('txt_city')">
                                    </td>
                              </tr>
                              <tr id=tr_state>
                                    <td>
                                          State:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_state" name="chk_state" checked=True><input type="text" size="20" id="txt_state" name="txt_state" onkeypress="vbs:Detect_Search_Field('txt_state')">
                                    </td>
                              </tr>
                              <tr id=tr_zipcode>
                                    <td>
                                          Zip Code:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_zipcode" name="chk_zipcode" checked=True><input type="text" size="20" id="txt_zipcode" name="txt_zipcode" onkeypress="vbs:Detect_Search_Field('txt_zipcode')">
                                    </td>
                              </tr>
                              <tr id=tr_country>
                                    <td>
                                          Country:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_country" name="chk_country" checked=True><input type="text" size="20" id="txt_country" name="txt_country" onkeypress="vbs:Detect_Search_Field('txt_country')">
                                          &nbsp&nbspMust search by 2 letter country code
                                    </td>
                              </tr>
                              <tr id=tr_homephone>
                                    <td>
                                          Home Phone:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_homephone" name="chk_homephone" checked=True><input type="text" size="20" id="txt_homephone" name="txt_homephone" onkeypress="vbs:Detect_Search_Field('txt_homephone')">
                                    </td>
                              </tr>
                              <tr id=tr_manager>
                                    <td>
                                          Manager:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_manager" name="chk_manager" checked=True><input type="hidden" size="20" id="txt_manager" name="txt_manager"><input type="text" size="20" id="txt_managerseen" name="txt_managerseen" onkeypress="vbs:Detect_Search_Field('txt_managerseen')">
                                    </td>
                              </tr>
                              <tr id=tr_whencreated>
                                    <td>
                                          Date Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_whencreated" name="chk_whencreated" checked=True><input type="text" size="40" id="txt_whencreated" name="txt_whencreated" onkeypress="vbs:Detect_Search_Field('txt_whencreated')"><input type=button value="Pick" onclick="DoCal('txt_whencreated')">
                                    </td>
                              </tr>
                              <tr id=tr_oupathuser>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathuser" name="chk_oupathuser" checked=True><input type="text" size="50" id="txt_oupathuser" name="txt_oupathuser" onkeypress="vbs:Detect_Search_Field('txt_oupathuser')">
                                    </td>
                              </tr>
                              <tr id=tr_lastlogintimestamp>
                                    <td>
                                          Last Login:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_lastlogintimestamp" name="chk_lastlogintimestamp" checked=True><input type="text" size="50" id="txt_lastlogintimestamp" name="txt_lastlogintimestamp" onkeypress="vbs:Detect_Search_Field('txt_lastlogintimestamp')">
                                    </td>
                              </tr>
                              <tr>
                                    <td colspan="2" align="center">
                                          <br>Showing record&nbsp
                                          <span id="span_currentrecord">
                                          0
                                          </span>
                                          &nbsp;of&nbsp;
                                          <span id="span_totalrecords">
                                          0
                                          </span>
                                          <br><br>
                                          <input type="button" value='||< First' name='btnFirstEvent'  onClick='vbs:First_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='<< Previous' name='btnPreviousEvent'  onClick='vbs:Previous_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Next >>' name='btnNextEvent'  onClick='vbs:Next_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Last >||' name='btnLastEvent'  onClick='vbs:Last_Event'><br><br>
                                          <input type="button" value='Email this record' name='btnEmailThisRecord'  onClick='vbs:Email_This_Record'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email all records' name='btnEmailAllRecords'  onClick='vbs:Email_All_Records'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email as attachment' name='btnEmailAsAttachment'  onClick='vbs:Email_As_Attachment'><br><br>
                                          <input type="button" value='Clear Form' name='btnClearForm'  onClick='vbs:Clear_Form("resetGroupLists")'>
                                          <input type="submit" value="Submit" name="btn_submit" onClick="vbs:Submit_Form('Main')">
                                          <input id="runbutton"  class="button" type="button" value="Save to" name="run_button" onClick="Runscript">
                                          <input id="runbutton"  class="button" type="button" value="Change PWD" name="bt1go">
                                          <input id="runbutton"  class="button" type="button" value="Enable/Disable User" name="bt2go">
                                    </td>
                              </tr>
                        </table>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset>
                  <LEGEND>Computer Information</LEGEND>
                  <table>
                              <tr id=tr_notes>
                                    <td valign="top">
                                         Machine Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_notes" name="chk_notes" checked=True><input type="text" size="40" id="txt_notes" name="txt_notes" onkeypress="vbs:Detect_Search_Field('txt_notes')">
<br>IP: <span id="span_computerip"> </span><br>
Status: <span id="span_computeronline"> </span>
                                    </td>
                              </tr>
                              <tr id=tr_computerserialno>
                                    <td>
                                         Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerserialno" name="chk_computerserialno" checked=True><input type="text" size="40" id="txt_computerserialno" name="txt_computerserialno" onkeypress="vbs:Detect_Search_Field('txt_computerserialno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacedmachine>
                                    <td>
                                         Replaced Machine:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedmachine" name="chk_replacedmachine" checked=True><input type="text" size="40" id="txt_replacedmachine" name="txt_replacedmachine">
                                    </td>
                              </tr>
                              <tr id=tr_replacedcomputerserialno>
                                    <td>
                                         Replaced Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedcomputerserialno" name="chk_replacedcomputerserialno" checked=True><input type="text" size="40" id="txt_replacedcomputerserialno" name="txt_replacedcomputerserialno">
                                    </td>
                              </tr>
                              <tr id=tr_oupathcomputer>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathcomputer" name="chk_oupathcomputer" checked=True><input type="text" size="40" id="txt_oupathcomputer" name="txt_oupathcomputer" onkeypress="vbs:Detect_Search_Field('txt_oupathcomputer')">
                                    </td>
                              </tr>
                              <tr id=tr_computeros>
                                    <td>
                                          Computer OS:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computeros" name="chk_computeros" checked=True><input type="text" size="19" id="txt_computeros" name="txt_computeros" onkeypress="vbs:Detect_Search_Field('txt_computeros')">
                                          <input type="text" size="18" id="txt_computerservicepack" name="txt_computerservicepack" onkeypress="vbs:Detect_Search_Field('txt_computerservicepack')">
                                    </td>
                              </tr>
                              <tr id=tr_computerdescription>
                                    <td>
                                         Description:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerdescription" name="chk_computerdescription" checked=True><input type="text" size="40" id="txt_computerdescription" name="txt_computerdescription" onkeypress="vbs:Detect_Search_Field('txt_computerdescription')">
                                    </td>
                              </tr>
                              <tr id=tr_computercreated>
                                    <td>
                                          Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computercreated" name="chk_computercreated" checked=True><input type="text" size="40" id="txt_computercreated" name="txt_computercreated" onkeypress="vbs:Detect_Search_Field('txt_computercreated')"><input type=button value="Pick" onclick="DoCal('txt_computercreated')">
                                    </td>
                              </tr>
                  </table>
                  </fieldset>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset id=tr_groupmembership>
                  <LEGEND><input type="checkbox" id="chk_groupmembership" name="chk_groupmembership" checked=True>Group Membership <span id="span_groupmembership"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_groupnames" name="lst_groupnames" onDblClick="vbs:Submit_Form('Group')">
                  
                  </select>
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_dgmembership>
                  <LEGEND><input type="checkbox" id="chk_dgmembership" name="chk_dgmembership" checked=True>Distribution Group Membership <span id="span_dgmembership"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_dgnames" name="lst_dgnames" onDblClick="vbs:Submit_Form('DistributionGroup')">
                  
                  </select>
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_managerlist>
                  <LEGEND><input type="checkbox" id="chk_managerlist" name="chk_managerlist" checked=True>Manager <span id="span_managerlist"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_managerlist" name="lst_managerlist" onDblClick="vbs:Submit_Form('ManagerList')">
                  
                  </select>
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_subordinates>
                  <LEGEND><input type="checkbox" id="chk_subordinates" name="chk_subordinates" checked=True>Subordinates <span id="span_subordinates"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_subordinates" name="lst_subordinates" onDblClick="vbs:Submit_Form('Subordinate')">
                  
                  </select>
                  </fieldset>
                  <br><br>
                  </td>
            </tr>
      </table>
 </body>

Open in new window

0
bsharath
Asked:
bsharath
  • 16
  • 8
1 Solution
 
rejoinderCommented:
2. A way to get all computers in the domain. To be shown. In a box. Search the whole Domain (Local only)

Done.
I also added filter box to reduce the number of items shown.  Filter acts like the other filter boxes - as you type, the list get reduced.

6. Any way to have an option to reset the local password of the machine i want i am quering.

Done.
There is a button called Reset next to the computer name box.  The computer name must be valid for this to work.  As you might know, any computer account that has been reset will have to be added to your domain again.
<head>
<title>User Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="User Information"
     BORDER="thin"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="MAXIMIZE"
     ID="oHTA"
>
<APPLICATION:HTA>
</head>
 
<script language="VBScript">
Const adVarChar = 200
Const VarCharMaxCharacters = 255
Const adFldIsNullable = 32
 
'http://www.experts-exchange.com/Programming/Languages/Q_23807915.html
 
Dim strEmailBCC
Dim strEmailServer
Dim arrSubjectText
Dim arrDomainNames
 
strEmailBCC         = "" 'Enter the BCC field as "Your Name <youremail@yourdomain.com>"
strEmailServer      = "MAILSERVER" 'Exchange server name
arrSubjectText      = array("This is subject text #1","This is subject text #2","This is subject text #3","This is subject text #4","This is subject text #5","This is subject text #6","This is subject text #7","This is subject text #8")
arrToSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
arrCCSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
arrBodySpecial      = array("Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here") 'Fill in the body text which will match the order the subject lines above.
arrCheckBoxSpecial  = array("Default","Default","Default","Default","Default","Default","Default","Default") 'Use the checkbox profile name to have the script match up the subject line to the checkbox profile you have stored.
strEmailFrom        = "" 'Leave Blank if the HTA should determine email address automatically
 
'Uncomment the next line to input your own domain names
'arrDomainNames      = array("DOMAIN","DC=subdomain1,DC=domain,DC=com")
 
boolAllowPing       = False 'Set to true to allow the interface to ping computers.
boolLookupLastLogin = False 'Set to true to allow the interface to query last logons
boolTableReports    = False 'Set to true to allow the interface to use table format reports
 
Dim arrRows
Dim strEmailFrom
Dim strEmailTo
Dim strEmailCC
Dim DataList
Dim globalstrSearchField
Dim globalstrSearchBtnPush
Dim FileName
Dim fModif
Dim LastChildMenu
Dim LastMenu
Dim globalstrQueryBuilder
 
if NOT IsArray(arrDomainNames) then
    GetDomainNames
End If
 
If strEmailFrom = "" Then
    strEmailFrom = mid(GetEmailAddresses(GetUsersEmailAddress),1,len(GetEmailAddresses(GetUsersEmailAddress))-1)
    strEmailFrom = GetUsersEmailAddress & " <" & strEmailFrom & ">"	'Getting email address from logged on user
End if
 
strEmailTo = GetUsersEmailAddress	'Get user name of logged on user so there is a default value when launched
strEmailCC = ""
 
DisplayTitle
Set LastChildMenu = Nothing
Set LastMenu = Nothing
 
Set oShell = CreateObject("WScript.Shell")
fTemp      = oShell.ExpandEnvironmentStrings("%TEMP%")
fAppData   = oShell.ExpandEnvironmentStrings("%APPDATA%")
 
Set MailboxList = CreateObject("ADOR.Recordset")
MailboxList.Fields.Append "legacyExchangeDN", adVarChar, VarCharMaxCharacters
MailboxList.Fields.Append "mailboxsize", adVarChar, VarCharMaxCharacters
MailboxList.Open
 
Set GroupMembershipDB = CreateObject("ADOR.Recordset")
GroupMembershipDB.Fields.Append "SAMAccountName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "PrimaryGroupToken", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "SAMAccountType", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "MemberDistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Open
 
Set DomainComputersDB = CreateObject("ADOR.Recordset")
DomainComputersDB.Fields.Append "CN", adVarChar, VarCharMaxCharacters, adFldIsNullable
DomainComputersDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
DomainComputersDB.Open
 
set dicGroupNumbers = CreateObject("Scripting.Dictionary")
set dicManagerList  = CreateObject("Scripting.Dictionary")
 
Sub GetDomainNames
    set objRootDSE   = GetObject("LDAP://RootDSE")
    strBase          = "<LDAP://cn=Partitions," & objRootDSE.Get("ConfigurationNamingContext") & ">;"
    strFilter        = "(&(objectcategory=crossRef)(systemFlags=3));"
    strAttrs         = "name,trustParent,nCName,dnsRoot,distinguishedName;"
    strScope         = "onelevel"
    set objConn      = CreateObject("ADODB.Connection")
    objConn.Provider = "ADsDSOObject"
    objConn.Open "Active Directory Provider"
    set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
    objRS.MoveFirst
    
    set arrDomainNames     = CreateObject("Scripting.Dictionary")
    set dicDomainHierarchy = CreateObject("Scripting.Dictionary")
    set dicDomainRoot      = CreateObject("Scripting.Dictionary")
    
    while not objRS.EOF 
        dicDomainRoot.Add objRS.Fields("name").Value, objRS.Fields("nCName").Value
        if objRS.Fields("trustParent").Value <> "" then
            arrDomainNames.Add objRS.Fields("name").Value, 0
            set objDomainParent = GetObject("LDAP://" & objRS.Fields("trustParent").Value)
            dicDomainHierarchy.Add objRS.Fields("name").Value,objDomainParent.Get("name")
       else 
            arrDomainNames.Add objRS.Fields("name").Value, 1
       end if
       objRS.MoveNext
    wend
    for each strDomain in arrDomainNames
        'msgbox strDomain
    next
End Sub
 
Sub Window_OnLoad
      'Uncomment the following lines to hide them from the GUI
      'tr_seatno.classname="HideFromGUI"
      'tr_replacementseatno.classname="HideFromGUI"
      'tr_building.classname="HideFromGUI"
      'tr_extensionno.classname="HideFromGUI"
      'tr_empid.classname="HideFromGUI"
      'tr_department.classname="HideFromGUI"
      'tr_designation.classname="HideFromGUI"
      'tr_name.classname="HideFromGUI"
      'tr_loginname.classname="HideFromGUI"
      'tr_email.classname="HideFromGUI"
      'tr_mailboxsize.classname="HideFromGUI"
      'tr_mailboxstore.classname="HideFromGUI"
      'tr_mobileno.classname="HideFromGUI"
      'tr_company.classname="HideFromGUI"
      'tr_address.classname="HideFromGUI"
      'tr_city.classname="HideFromGUI"
      'tr_state.classname="HideFromGUI"
      'tr_zipcode.classname="HideFromGUI"
      'tr_country.classname="HideFromGUI"
      'tr_homephone.classname="HideFromGUI"
      'tr_manager.classname="HideFromGUI"
      'tr_whencreated.classname="HideFromGUI"
      'tr_oupathuser.classname="HideFromGUI"
      'tr_lastlogintimestamp.classname="HideFromGui"
      'tr_notes.classname="HideFromGUI"
      'tr_computerserialno.classname="HideFromGUI"
      'tr_replacedmachine.classname="HideFromGUI"
      'tr_replacedcomputerserialno.classname="HideFromGUI"
      'tr_oupathcomputer.classname="HideFromGUI"
      'tr_computeros.classname="HideFromGUI"
      'tr_computerdescription.classname="HideFromGUI"
      'tr_computercreated.classname="HideFromGUI"
      'tr_groupmembership.classname="HideFromGUI"
      'tr_dgmembership.classname="HideFromGUI"
      'tr_managerlist.classname="HideFromGUI"
      'tr_subordinates.classname="HideFromGUI"
      'tr_domaincomputers.classname="HideFromGUI"
      
      TestToSeeWhatLinesAreHidden
      
      btnFirstEvent.Disabled = True
      btnPreviousEvent.Disabled = True
      btnNextEvent.Disabled = True
      btnLastEvent.Disabled = True
      btnEmailThisRecord.Disabled = True
      btnEMailAllRecords.Disabled = True
      btnEmailAsAttachment.Disabled = True
      txt_EmailTo.Value = strEmailTo
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      FillGroupList
      FillManagerList
      FillSubjectList
      FillDomainComputers
      GetChkProfiles
      GetMailboxDetails
      chk_TableReports.Checked = boolTableReports
      chk_LookupLastLogin.Checked = boolLookupLastLogin
      chk_AllowPings.Checked = boolAllowPing
      txt_EmailSubject_OnChange
End Sub
 
Sub TestToSeeWhatLinesAreHidden
      'Test to see what lines are hidden and uncheck the boxes
      if tr_seatno.classname="HideFromGUI" then chk_seatno.Checked = False
      if tr_replacementseatno.classname="HideFromGUI" then chk_replacementseatno.Checked = False
      if tr_building.classname="HideFromGUI" then chk_building.Checked = False
      if tr_extensionno.classname="HideFromGUI" then chk_extensionno.Checked = False
      if tr_empid.classname="HideFromGUI" then chk_empid.Checked = False
      if tr_department.classname="HideFromGUI" then chk_department.Checked = False
      if tr_designation.classname="HideFromGUI" then chk_designation.Checked = False
      if tr_name.classname="HideFromGUI" then chk_name.Checked = False
      if tr_loginname.classname="HideFromGUI" then chk_loginname.Checked = False
      if tr_email.classname="HideFromGUI" then chk_email.Checked = False
      if tr_mailboxsize.classname="HideFromGUI" then chk_mailboxsize.Checked = False
      if tr_mailboxstore.classname="HideFromGUI" then chk_mailboxstore.Checked = False
      if tr_mobileno.classname="HideFromGUI" then chk_mobileno.Checked = False
      if tr_company.classname="HideFromGUI" then chk_company.Checked = False
      if tr_address.classname="HideFromGUI" then chk_address.Checked = False
      if tr_city.classname="HideFromGUI" then chk_city.Checked = False
      if tr_state.classname="HideFromGUI" then chk_state.Checked = False
      if tr_zipcode.classname="HideFromGUI" then chk_zipcode.Checked = False
      if tr_country.classname="HideFromGUI" then chk_country.Checked = False
      if tr_homephone.classname="HideFromGUI" then chk_homephone.Checked = False
      if tr_manager.classname="HideFromGUI" then chk_manager.Checked = False
      if tr_whencreated.classname="HideFromGUI" then chk_whencreated.Checked = False
      if tr_oupathuser.classname="HideFromGUI" then chk_oupathuser.Checked = False
      if tr_lastlogintimestamp.classname="HideFromGUI" then chk_lastlogintimestamp.Checked = False
      if tr_notes.classname="HideFromGUI" then chk_notes.Checked = False
      if tr_computerserialno.classname="HideFromGUI" then chk_computerserialno.Checked = False
      if tr_replacedmachine.classname="HideFromGUI" then chk_replacedmachine.Checked = False
      if tr_replacedcomputerserialno.classname="HideFromGUI" then chk_replacedcomputerserialno.Checked = False
      if tr_oupathcomputer.classname="HideFromGUI" then chk_oupathcomputer.Checked = False
      if tr_computeros.classname="HideFromGUI" then chk_computeros.Checked = False
      if tr_computerdescription.classname="HideFromGUI" then chk_computerdescription.Checked = False
      if tr_computercreated.classname="HideFromGUI" then chk_computercreated.Checked = False
      if tr_groupmembership.classname="HideFromGUI" then chk_groupmembership.Checked = False
      if tr_dgmembership.classname="HideFromGUI" then chk_dgmembership.Checked = False
      if tr_managerlist.classname="HideFromGUI" then chk_managerlist.Checked = False
      if tr_subordinates.classname="HideFromGUI" then chk_subordinates.Checked = False
End sub
 
Sub Clear_Form(resetGroupLists)
      txt_seatno.Value = ""
      txt_seatno.style.backgroundColor="#FFFFFF"
      txt_seatno.Disabled = False
      txt_replacementseatno.Value = ""
      txt_replacementseatno.style.backgroundColor="#FFFFFF"
      txt_replacementseatno.Disabled = False
      txt_building.Value = ""
      txt_building.style.backgroundColor="#FFFFFF"
      txt_building.Disabled = False
      txt_extensionno.Value = ""
      txt_extensionno.style.backgroundColor="#FFFFFF"
      txt_extensionno.Disabled = False
      txt_empid.Value = ""
      txt_empid.style.backgroundColor="#FFFFFF"
      txt_empid.Disabled = False
      txt_department.Value = ""
      txt_department.style.backgroundColor="#FFFFFF"
      txt_department.Disabled = False
      txt_designation.Value = ""
      txt_designation.style.backgroundColor="#FFFFFF"
      txt_designation.Disabled = False
      txt_name.Value = ""
      txt_name.style.backgroundColor="#FFFFFF"
      txt_name.Disabled = False
      txt_loginname.Value = ""
      txt_loginname.style.backgroundColor="#FFFFFF"
      txt_loginname.Disabled = False
      txt_email.Value = ""
      txt_email.style.backgroundColor="#FFFFFF"
      txt_email.Disabled = False
      txt_mailboxsize.Value = ""
      txt_mailboxsize.style.backgroundColor="#FFFFFF"
      txt_mailboxsize.Disabled = False
      txt_mailboxstore.Value = ""
      txt_mailboxstore.style.backgroundColor="#FFFFFF"
      txt_mailboxstore.Disabled = False
      txt_notes.Value = ""
      txt_notes.style.backgroundColor="#FFFFFF"
      txt_notes.Disabled = False
      txt_computerserialno.Value = ""
      txt_computerserialno.style.backgroundColor="#FFFFFF"
      txt_computerserialno.Disabled = False
      txt_replacedmachine.Value = ""
      txt_replacedmachine.Disabled = False
      txt_replacedmachine.style.backgroundcolor="#FFFFFF"
      txt_replacedcomputerserialno.value = ""
      txt_replacedcomputerserialno.Disabled = False
      txt_replacedcomputerserialno.Style.backgroundcolor="#FFFFFF"
      txt_oupathcomputer.Value = ""
      txt_oupathcomputer.style.backgroundColor="#FFFFFF"
      txt_oupathcomputer.Disabled = False
      txt_computeros.Value = ""
      txt_computeros.Style.backgroundColor="#FFFFFF"
      txt_computeros.Disabled = False
      txt_computerservicepack.Value = ""
      txt_computerservicepack.Style.backgroundColor="#FFFFFF"
      txt_computerservicepack.Disabled = False
      txt_computercreated.Value = ""
      txt_computercreated.Style.backgroundColor="#FFFFFF"
      txt_computercreated.Disabled = False
      txt_computerdescription.Value = ""
      txt_computerdescription.Style.backgroundColor="#FFFFFF"
      txt_computerdescription.Disabled = False
      txt_mobileno.Value = ""
      txt_mobileno.style.backgroundColor="#FFFFFF"
      txt_mobileno.Disabled = False
      txt_company.Value = ""
      txt_company.style.backgroundColor="#FFFFFF"
      txt_company.Disabled = False
      txt_address.Value = ""
      txt_address.style.backgroundColor="#FFFFFF"
      txt_address.Disabled = False
      txt_city.Value = ""
      txt_city.style.backgroundColor="#FFFFFF"
      txt_city.Disabled = False
      txt_state.Value = ""
      txt_state.style.backgroundColor="#FFFFFF"
      txt_state.Disabled = False
      txt_zipcode.Value = ""
      txt_zipcode.style.backgroundColor="#FFFFFF"
      txt_zipcode.Disabled = False
      txt_country.Value = ""
      txt_country.style.backgroundColor="#FFFFFF"
      txt_country.Disabled = False
      txt_homephone.Value = ""
      txt_homephone.style.backgroundColor="#FFFFFF"
      txt_homephone.Disabled = False
      txt_manager.Value = ""
      txt_manager.style.backgroundColor="#FFFFFF"
      txt_manager.Disabled = False
      txt_managerseen.Value = ""
      txt_managerseen.style.backgroundColor="#FFFFFF"
      txt_managerseen.Disabled = False
      txt_whencreated.Value = ""
      txt_whencreated.style.backgroundColor="#FFFFFF"
      txt_whencreated.Disabled = False
      txt_oupathuser.Value = ""
      txt_oupathuser.style.backgroundColor="#FFFFFF"
      txt_oupathuser.Disabled = False
      txt_lastlogintimestamp.Value = ""
      txt_lastlogintimestamp.style.backgroundcolor="#FFFFFF"
      txt_lastlogintimestamp.Disabled = False
      txt_FilterSecurityGroup.Value = ""
      txt_FilterSecurityGroup.style.backgroundcolor="#FFFFFF"
      txt_FilterSecurityGroup.Disabled = False
      txt_filterdgmembership.Value = ""
      txt_filterdgmembership.style.backgroundcolor="#FFFFFF"
      txt_filterdgmembership.Disabled = False
      txt_filtermanagerlist.Value = ""
      txt_filtermanagerlist.style.backgroundcolor="#FFFFFF"
      txt_filtermanagerlist.Disabled = False
      txt_filterdomaincomputers.Value = ""
      txt_filterdomaincomputers.style.backgroundcolor="#FFFFFF"
      txt_filterdomaincomputers.Disabled = False
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      span_currentrecord.InnerHTML = "0"
      span_totalrecords.InnerHTML = "0"
      span_computerip.InnerHTML = ""
      span_computerOnline.InnerHTML = ""
      span_enabled.InnerHTML = ""
      span_userorcontact.InnerHTML = ""
      if lcase(resetGroupLists) = lcase("resetGroupLists") then
          GroupMembershipDB.Filter = ""
          GroupMembershipDB.MoveFirst
          Do While Not GroupMembershipDB.EOF
              GroupMembershipDB.Delete
              GroupMembershipDB.MoveNext
          Loop
          FillGroupList
          populatedomaincomputers
      end if
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      PopulateManagerList
End Sub
 
Sub Submit_Form(btnPush)
 
      arrFields = Array(_
            "txt_seatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_notes", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_oupathuser", _
            "txt_computerserialno", _
            "txt_whencreated", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computercreated", _
            "txt_filtersecuritygroup", _
            "txt_filterdgmembership", _
            "txt_filtermanagerlist", _
            "txt_filterdomaincomputers" _
      )
      
      boolValid = False
      For Each strField In arrFields
            If Eval(strField & ".Disabled") = True Then
                  boolValid = True
            End If
            If Eval(strField & ".Disabled") = False Then
                  strCurrentField = strField
            End If
      Next
      
      If boolValid = False Then strCurrentField = "INVALID"
      
      Select Case strCurrentField
            Case "txt_seatno"
                  If txt_seatno.Value = "" Then
                  	strSearchField = "(info=*)"
                  Else
                  	strSearchField = "(info=*" & txt_seatno.Value & "*)"
                  End If
            Case "txt_building"
                  If txt_building.Value = "" Then
                  	strSearchField = "(physicalDeliveryOfficeName=*)"
                  Else
                  	strSearchField = "(physicalDeliveryOfficeName=*" & txt_building.Value & "*)"
                  End If
            Case "txt_extensionno"
                  If txt_extensionno.Value = "" Then
                        strSearchField = "(telephoneNumber=*)"
                  Else
                        strSearchField = "(telephoneNumber=*" & txt_extensionno.Value & "*)"
                  End If
            Case "txt_empid"
                  If txt_empid.Value = "" Then
                        strSearchField = "(description=*)"
                  Else
                        strSearchField = "(description=*" & txt_empid.Value & "*)"
                  End If
            Case "txt_department"
                  If txt_department.Value = "" Then
                        strSearchField = "(department=*)"
                  Else
                        strSearchField = "(department=*" & txt_department.Value & "*)"
                  End If
            Case "txt_designation"
                  If txt_designation.Value = "" Then
                        strSearchField = "(title=*)"
                  Else
                        strSearchField = "(title=*" & txt_designation.Value & "*)"
                  End If
            Case "txt_name"
                  If txt_name.Value = "" Then
                        strSearchField = "(cn=*)"
                  Else
                        strSearchField = "(cn=*" & txt_name.Value & "*)"
                  End If
            Case "txt_loginname"
                  If txt_loginname.Value = "" Then
                        strSearchField = "(samAccountName=*)"
                  Else
                        strSearchField = "(samAccountName=*" & txt_loginname.Value & "*)"
                  End If
            Case "txt_email"
                  If txt_email.Value = "" Then
                        strSearchField = "(mail=*)"
                  Else
                        strSearchField = "(mail=*" & txt_email.Value & "*)"
                  End If
            Case "txt_notes"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_notes.Value & "*)"
                  End If
            Case "txt_mobileno"
                  If txt_mobileno.Value = "" Then
                        strSearchField = "(mobile=*)"
                  Else
                        strSearchField = "(mobile=*" & txt_mobileno.Value & "*)"
                  End If
            Case "txt_company"
                  If txt_company.Value = "" Then
                        strSearchField = "(company=*)"
                  Else
                        strSearchField = "(company=*" & txt_company.Value & "*)"
                  End If
            Case "txt_address"
                  If txt_address.Value = "" Then
                        strSearchField = "(streetAddress=*)"
                  Else
                        strSearchField = "(streetAddress=*" & txt_address.Value & "*)"
                  End If
            Case "txt_city"
                  If txt_city.Value = "" Then
                        strSearchField = "(l=*)"
                  Else
                        strSearchField = "(l=*" & txt_city.Value & "*)"
                  End If
            Case "txt_state"
                  If txt_state.Value = "" Then
                        strSearchField = "(st=*)"
                  Else
                        strSearchField = "(st=*" & txt_state.Value & "*)"
                  End If
            Case "txt_zipcode"
                  If txt_zipcode.Value = "" Then
                        strSearchField = "(postalCode=*)"
                  Else
                        strSearchField = "(postalCode=*" & txt_zipcode.Value & "*)"
                  End If
            Case "txt_country"
                  If txt_country.Value = "" Then
                        strSearchField = "(c=*)"
                  Else
                        strSearchField = "(c=*" & txt_country.Value & "*)"
                  End If
            Case "txt_homephone"
                  If txt_homephone.Value = "" Then
                        strSearchField = "(homePhone=*)"
                  Else
                        strSearchField = "(homePhone=*" & txt_homephone.Value & "*)"
                  End If
            Case "txt_managerseen"
                  If txt_managerseen.Value = "" Then
                        strSearchField = "(manager=*)"
                  Else
                        strSearchField = GetManagerDN(txt_managerseen.Value)
                  End If
            Case "txt_oupathuser"
                  If txt_oupathuser.Value <> "" Then
                        strSearchField = GetOUMembers(txt_oupathuser.Value)
                  End If
            Case "txt_whencreated"
                  If txt_whencreated.Value = "" Then
                        strSearchField = "(whenCreated=*)"
                  Else
                        if NOT IsDate(txt_whencreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strWhenCreated = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
                            strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
                        end if
                  End If
            Case "txt_computerserialno"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_computerserialno.Value & "*)"
                  End If
            Case "txt_oupathcomputer"
                  If txt_oupathcomputer.Value = "" then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersBasedOnOU(txt_oupathcomputer.Value)
                  end if
            Case "txt_computeros"
                  If txt_computeros.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersForOSQuery(txt_computeros.Value)
                  End If
            Case "txt_computercreated"
                  If txt_computercreated.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        if NOT IsDate(txt_computercreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strSearchField = GetComputersForDateCreatedQuery(txt_computercreated.Value)
                        End If
                  End If
            Case "txt_filtersecuritygroup"
                  if lst_groupnames.Options.Length = 1 then
                        lst_groupnames.Options(0).Selected = True
                        btnPush = "Group"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filterdgmembership"
                  if lst_dgnames.Options.Length = 1 then
                        lst_dgnames.Options(0).Selected = True
                        btnPush = "DistributionGroup"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filtermanagerlist"
                  if lst_managerlist.Options.Length = 1 then
                        lst_managerlist.Options(0).Selected = True
                        btnPush = "ManagerList"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filterdomaincomputers"
                  if lst_domaincomputers.Options.Length = 1 then
                        strSearchField = "(info=*" & lst_domaincomputers.Options(0).Value & "*)"
                  else
                        strSearchField = "INVALID"
                  end if
            Case Else
                  strSearchField = "INVALID"
      End Select
      
      if btnPush = "Disabled" then
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)"
      end if
      
      if btnPush = "Group" then
          For i = 0 to (lst_groupnames.Options.Length - 1)
              If (lst_groupnames.Options(i).Selected) Then
                  arrGroupNames = split(lst_groupnames.Options(i).Value,";")
                  sprimaryGroupID = arrGroupNames(0)
                  sMemberOf = arrGroupNames(1)
              End If
          Next
          if sprimaryGroupID = 513 then
              strSearchField = "(primaryGroupID=" & sprimaryGroupID & ")"
          else
              strSearchField = "(memberOf=" & sMemberOf & ")"
          end if
      end if
      
      if btnPush = "DistributionGroup" then
          For i = 0 to (lst_dgnames.Options.Length - 1)
              If (lst_dgnames.Options(i).Selected) Then
                  arrGroupNames = split(lst_dgnames.Options(i).Value,";")
                  sprimaryGroupID = arrGroupNames(0)
                  sMemberOf = arrGroupNames(1)
              End If
          Next
          if sprimaryGroupID = 513 then
              strSearchField = "(primaryGroupID=" & sprimaryGroupID & ")"
          else
              strSearchField = "(memberOf=" & sMemberOf & ")"
          end if
      end if
      
      if btnPush = "ManagerList" then
          For i = 0 to (lst_ManagerList.Options.Length - 1)
              If (lst_ManagerList.Options(i).Selected) Then
                  strSearchField = "(distinguishedname=" & lst_ManagerList.Options(i).Value & ")" 
              End If
          Next
      end if
      
      if btnPush = "Subordinate" then
          For i = 0 to (lst_subordinates.Options.Length - 1)
              If (lst_subordinates.Options(i).Selected) Then
                  arrSubordinateNames = split(lst_subordinates.Options(i).Value,";")
                  strSearchField = "(samAccountName=*" & arrSubordinateNames(0) & "*)"
              End If
          Next
      end if
      
      if btnPush = "DisabledToday" then
          strWhenChanged = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)(whenChanged>=" & strWhenChanged & "000000.0Z)(whenChanged<=" & strWhenChanged & "235959.0Z)"
      end if
      
      if btnPush = "FileOpen" then
          strSearchField = globalStrSearchField
          btnPush = globalStrSearchBtnPush
      End if
      
      boolLogonSearch = False
      dmtDateToCompare = Date()
      
      if InStr(btnPush,"Logon:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolLogonSearch = True
          intNumberOfDays = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
          dmtDateToCompare = Date() - intNumberOfDays
          
          if NOT chk_LookupLastLogin.Checked then
              chk_LookupLastLogin.Checked = True
              boolLookupLastLogin = True
          end if
          
      end if
      
      boolMailboxSizeSearch = False
      
      if InStr(btnPush,"MailboxSize:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolMailboxSizeSearch = True
          intMailboxSizeToCompare = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
      end if
      
      Clear_Form ""
      
      If strSearchField <> "INVALID" Then
            Set adoCommand = CreateObject("ADODB.Command")
            Set adoConnection = CreateObject("ADODB.Connection")
            adoConnection.Provider = "ADsDSOObject"
            adoConnection.Open "Active Directory Provider"
            adoCommand.ActiveConnection = adoConnection
            
            boolFoundRecords = False
            
            for each strDomain in arrDomainNames
                  ' Search entire Active Directory domain.
                  strBase = "<LDAP://" & strDomain & ">"
                  
                  strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
 
                  ' Comma delimited list of attribute values to retrieve.
                  if boolLookupLastLogin then
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID,lastLogon"
                  else
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID"
                  end if
                  ' Construct the LDAP syntax query.
                  strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                  adoCommand.CommandText = strQuery
                  adoCommand.Properties("Page Size") = 100
                  adoCommand.Properties("Timeout") = 30
                  adoCommand.Properties("Cache Results") = False
                  adoCommand.Properties("Sort On") = "cn"
                  ' Run the query.
                  Set adoRecordset = adoCommand.Execute
                  ' Enumerate the resulting recordset.
                  strDetails = ""
                  If Not adoRecordset.EOF Then
                        boolFoundRecords = True
                        Do Until adoRecordset.EOF
                              mailboxlist.filter = "legacyExchangeDN = '" & adoRecordset.Fields("legacyExchangeDN").Value & "'"
                              if NOT mailboxlist.EOF then
                                    intMailboxSize = mailboxlist.fields.Item("mailboxsize")
                              else
                                    intMailboxSize = "0"
                              End if
                              if boolLookupLastLogin then
                                    if NOT IsNull(adoRecordset.Fields("lastLogon").Value) then
                                          Set objLastLogon = adoRecordset.Fields("lastLogon").Value
                                          intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart 
                                          intLastLogonTime = intLastLogonTime / (60 * 10000000)
                                          intLastLogonTime = intLastLogonTime / 1440
                                          intLastLogonTime = intLastLogonTime + #1/1/1601#
                                          if intLastLogonTime = #1/1/1601# then
                                                intLastLogonTime = ""
                                          end if
                                    else
                                          intLastLogonTime = ""
                                    end if
                              else
                                    intLastLogonTime = ""
                              end if
                              if NOT IsDate(intLastLogonTime) then
                                    dmtDateToCompareTo = dmtDateToCompare
                              else
                                    dmtDateToCompareTo = intLastLogonTime
                              end if
                              if (CDate(dmtDateToCompareTo) >= CDate(dmtDateToCompare)) AND boolLogonSearch then
                                    'Do nothing
                              else
                                    if (CInt(intMailboxSize) < CInt(intMailboxSizeToCompare)) AND boolMailboxSizeSearch then
                                          'Do nothing
                                    else
                                          If strDetails <> "" Then strDetails = strDetails & "|TR|"
                                          if adoRecordset.Fields("userAccountControl").Value AND 2 then
                                                strEnabled = "Disabled"
                                          else
                                                strEnabled = "Enabled"
                                          End If
                                          strMachineName = ""
                                          strBuilding = ""
                                          strSerialNumber = ""
                                          If IsNull(adoRecordset.Fields("Info").Value) = False Then
                                                arrNotesField = Split(adoRecordset.Fields("Info").Value,vbCRLF)
                                                for each strLine in arrNotesField
                                                      if InStr(UCase(strLine),"MACHINE NAME : ") then
                                                            strMachineName = trim(mid(strLine,15))
                                                      End if
                                                      if InStr(UCase(strLine),"LOCATION : ") then
                                                            strBuilding = trim(mid(strLine,11))
                                                      End if
                                                      if InStr(UCase(strLine),"SERIAL NO : ") then
                                                            strSerialNumber = trim(mid(strLine,12))
                                                      End if
                                                next
                                                strDetails = strDetails & replace(strBuilding,vbCRLF,"")
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("physicalDeliveryOfficeName").Value &_
                                          "|TD|" & adoRecordset.Fields("TelephoneNumber").Value
                                          If IsNull(adoRecordset.Fields("Description").Value) = False Then
                                                strDetails = strDetails & "|TD|" & Join(adoRecordset.Fields("description").Value)
                                          Else
                                                strDetails = strDetails & "|TD|"
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("Department").Value &_
                                          "|TD|" & adoRecordset.Fields("Title").Value &_
                                          "|TD|" & Replace(adoRecordset.Fields("cn").Value, "CN=", "") &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("mail").Value &_
                                          "|TD|" & strMachineName &_
                                          "|TD|" & adoRecordset.Fields("Mobile").Value &_
                                          "|TD|" & adoRecordset.Fields("company").Value &_
                                          "|TD|" & adoRecordset.Fields("streetAddress").Value &_
                                          "|TD|" & adoRecordset.Fields("l").Value &_
                                          "|TD|" & adoRecordset.Fields("st").Value &_
                                          "|TD|" & adoRecordset.Fields("postalCode").Value &_
                                          "|TD|" & adoRecordset.Fields("c").Value &_
                                          "|TD|" & adoRecordset.Fields("homePhone").Value &_
                                          "|TD|" & adoRecordset.Fields("manager").Value &_
                                          "|TD|" & adoRecordset.Fields("whenCreated").Value &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("distinguishedName").Value &_
                                          "|TD|" & intLastLogonTime &_
                                          "|TD|" & strSerialNumber &_
                                          "|TD|" & UCASE(strEnabled) &_
                                          "|TD|" & intMailboxSize &_
                                          "|TD|" & GetMailboxStore(adoRecordset.Fields("homeMDB").Value) &_
                                          "|TD|" & adoRecordset.Fields("primaryGroupID").Value
                                          strDetails = replace(strDetails,vbCRLF,"")
                                    end if
                              end if
                              adoRecordset.MoveNext
                        Loop
                  End If
            next
            
            if NOT boolFoundRecords then
                  MsgBox "No records were found"
                  span_currentrecord.InnerHTML = 0
                  span_totalrecords.InnerHTML  = 0
            else
                  arrRows = ""
                  arrRows = Split(strDetails, "|TR|")
                  If UBound(arrRows) < 0 Then
                        span_currentrecord.InnerHTML = 0
                        span_totalrecords.InnerHTML = 0
                  Else
                        span_currentrecord.InnerHTML = 1
                        Get_Event
                        span_totalrecords.InnerHTML = UBound(arrRows)+1
                  End If
            End if
            
            ' Clean up.
            adoRecordset.Close
            Set adoRecordset = Nothing
            
            adoConnection.Close
      
            If strDetails = "" Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = True
                  btnEMailAllRecords.Disabled = True
                  btnEmailAsAttachment.Disabled = True
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Hidden"
                  btnEMailAllRecords.Style.Visibility = "Hidden"
                  btnEmailAsAttachment.Style.Visibility = "Hidden"
            ElseIf UBound(arrRows) = 0 Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            Else
                  btnFirstEvent.Disabled = False
                  btnPreviousEvent.Disabled = False
                  btnNextEvent.Disabled = False
                  btnLastEvent.Disabled = False
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Visible"
                  btnPreviousEvent.Style.Visibility = "Visible"
                  btnNextEvent.Style.Visibility = "Visible"
                  btnLastEvent.Style.Visibility = "Visible"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            End If
            globalStrSearchBtnPush = BtnPush
            globalstrSearchField = strSearchField
            if chk_qbrecorder.Checked then
                  AddToQueryBuilder
            end if
      Else
            MsgBox "Please type a search request into one of the fields, then click Submit."
      End If
 
      if InStr(Join(arrFields),strCurrentField) then
            if strSearchField <> "INVALID" then
                  execute(strCurrentField & ".focus")
                  execute(strCurrentField & ".select()")
            end if
      end if
End Sub
 
Sub Get_Event
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	txt_seatno.Value = arrData(0)
	txt_building.Value = arrData(1)
	txt_extensionno.Value = arrData(2)
	txt_empid.Value = arrData(3)
	txt_department.Value = arrData(4)
	txt_designation.Value = arrData(5)
	txt_name.Value = arrData(6)
	txt_loginname.Value = arrData(7)
	txt_email.Value = arrData(8)
        txt_mailboxsize.Value = arrData(25)
        txt_mailboxstore.Value = arrData(26)
	txt_notes.Value = arrData(9)
        if boolAllowPing then PingComputer arrData(9)
        txt_computerserialno.Value = arrData(23)
        arrTemp = GetComputerInfo(arrData(9))
	if IsArray(arrTemp) then
	        txt_oupathcomputer.value = GetOUPath(replace(arrTemp(0),"""",""))
	        txt_computeros.value = replace(arrTemp(1),"""","")
	        txt_computerservicepack.value = replace(arrTemp(2),"""","")
	        txt_computerdescription.value = replace(arrTemp(4),"""","")
	        txt_computercreated.value = replace(arrTemp(3),"""","")
	else
	        txt_oupathcomputer.value = ""
	        txt_computeros.value = ""
	        txt_computerservicepack.value = ""
	        txt_computerdescription.value = ""
	        txt_computercreated.value = ""
	End if
	txt_mobileno.Value = arrData(10)
	txt_company.Value = arrData(11)
	txt_address.Value = arrData(12)
	txt_city.Value = arrData(13)
	txt_state.Value = arrData(14)
	txt_zipcode.Value = arrData(15)
	txt_country.Value = arrData(16)
	txt_homephone.Value = arrData(17)
	txt_manager.Value = arrData(18)
        For Each objOption in lst_managerlist.Options
            objOption.RemoveNode
        Next
        span_managerlist.InnerHTML = "(0)"
        if txt_manager.Value <> "" then
            txt_managerseen.Value = mid(txt_manager.Value,4,instr(txt_manager.Value,",")-4)
            set newOption = document.createElement("OPTION")
            newOption.Text = txt_managerseen.Value & " (" & GetSubordinateNumbers(txt_manager.Value) & ")"
            newOption.Value = txt_manager.Value
            lst_managerlist.Add newOption
            span_managerlist.InnerHTML = "(1)"
        else
            txt_managerseen.Value = txt_manager.Value
        end if
	txt_whencreated.Value = arrData(19)
        txt_oupathuser.value = GetOUPath(arrData(21))
        txt_lastlogintimestamp.value = arrData(22)
        span_enabled.InnerHTML = arrData(24)
        if txt_loginname.Value <> "" then
            span_userorcontact.InnerHTML = "USER"
        else
            span_userorcontact.InnerHTML = "CONTACT"
        end if
        FillGroupMembershipList arrData(21), arrData(27)
End Sub
 
Sub First_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML < 1 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = 1 Then
                  MsgBox "You are already viewing the first record."
            Else
                  span_currentrecord.InnerHTML = 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Previous_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_currentrecord.InnerHTML > 1 Then
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML - 1
                  Get_Event
            ElseIf span_currentrecord.InnerHTML = 1 Then
                        MsgBox "You are already viewing the first record."
            Else
                  MsgBox "There are no records to display"
            End If
      End If
 
End Sub
 
Sub Next_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records for to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                  MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML + 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Last_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                        MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_totalrecords.InnerHTML
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Detect_Search_Field(strCurrentField)
      arrFields = Array(_
            "txt_seatno", _
            "txt_replacementseatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_mailboxsize", _
            "txt_mailboxstore", _
            "txt_notes", _
            "txt_computerserialno", _
            "txt_replacedmachine", _
            "txt_replacedcomputerserialno", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computerservicepack", _
            "txt_computerdescription", _
            "txt_computercreated", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_whencreated", _
            "txt_oupathuser", _
            "txt_lastlogintimestamp", _
            "txt_filtersecuritygroup", _
            "txt_filterdgmembership", _
            "txt_filtermanagerlist", _
            "txt_filterdomaincomputers" _
      )
      
      For Each strField In arrFields
            If LCase(strField) <> LCase(strCurrentField) Then
                  Execute strField & ".style.backgroundColor=""#D3D3D3"""
                  Execute strField & ".Disabled = True"
            End If
      Next
End Sub
 
Function CreateHeaderRow(CSVorTABLE)
    Dim arrHeader()
    x = 0
    if chk_seatno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Seat No"""
        x = x + 1
    end if
    
    if chk_building.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Building"""
        x = x + 1
    end if
    
    if chk_extensionno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Extension"""
        x = x + 1
    end if
    
    if chk_empid.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Emp ID"""
        x = x + 1
    end if
    
    if chk_department.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Department"""
        x = x + 1
    end if
    
    if chk_designation.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Designation"""
        x = x + 1
    end if
         
    if chk_name.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """User Name"""
        x = x + 1
    end if
    
    if chk_loginname.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Login Name"""
        x = x + 1
    end if
    
    if chk_email.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Email Address"""
        x = x + 1
    end if
    
    if chk_mailboxsize.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Size (MB)"""
        x = x + 1
    end if
    
    if chk_mailboxstore.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Store"""
        x = x + 1
    end if
    
    if chk_notes.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer"""
        x = x + 1
    end if
    
    if chk_computerserialno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Serial No"""
        x = x + 1
    end if
    
    if chk_oupathcomputer.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - Computer"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer OS"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Service Pack"""
        x = x + 1
    end if
    
    if chk_computerdescription.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Description"""
        x = x + 1
    end if
    
    if chk_computercreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Account Created"""
        x = x + 1
    end if
    
    if chk_mobileno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mobile"""
        x = x + 1
    end if
    
    if chk_company.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Company"""
        x = x + 1
    end if
    
    if chk_address.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Address"""
        x = x + 1
    end if
    
    if chk_city.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """City"""
        x = x + 1
    end if
    
    if chk_state.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """State"""
        x = x + 1
    end if
    
    if chk_zipcode.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Zip Code"""
        x = x + 1
    end if
    
    if chk_country.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Country"""
        x = x + 1
    end if
    
    if chk_homephone.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Home Phone"""
        x = x + 1
    end if
    
    if chk_manager.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Manager"""
        x = x + 1
    end if
    
    if chk_subordinates.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Subordinates"""
        x = x + 1
    end if
    
    if chk_whencreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Date Created"""
        x = x + 1
    end if
    
    if chk_oupathuser.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - User"""
        x = x + 1
    end if
    
    if chk_lastlogintimestamp.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Last Logon"""
        x = x + 1
    end if
    
    if chk_groupmembership.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Group Membership"""
        x = x + 1
    end if
 
    if CSVorTABLE <> "" then
        strHeader = strHeader & "<tr>"
        for n = 0 to UBound(arrHeader)-1
            strHeader = strHeader & "<td valign=""top"" align=""left""><b>" & replace(arrHeader(n),"""","") & "</b></td>"
        next
        strHeader = strHeader & "</tr>" & vbCRLF
    else
        strHeader = Join(arrHeader,",")
    end if
    CreateHeaderRow = strHeader
End Function
 
Function PopulateTableForCSV(CSVorTABLE)
    For intRow = LBound(arrRows) To UBound(arrRows)
        arrData = Split(arrRows(intRow), "|TD|")
        x = 0
        if chk_seatno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(0) & """"
            x = x + 1
        end if
        
        if chk_building.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(1) & """"
            x = x + 1
        end if
        
        if chk_extensionno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(2) & """"
            x = x + 1
        end if
        
        if chk_empid.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(3) & """"
            x = x + 1
        end if
        
        if chk_department.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(4) & """"
            x = x + 1
        end if
         
        if chk_designation.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(5) & """"
            x = x + 1
        end if
        
        if chk_name.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(6) & """"
            x = x + 1
        end if
        
        if chk_loginname.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(7) & """"
            x = x + 1
        end if
        
        if chk_email.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(8) & """"
            x = x + 1
        end if
        
        if chk_mailboxsize.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(25) & """"
            x = x + 1
        end if
        
        if chk_mailboxstore.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(26) & """"
            x = x + 1
        end if
        
        if chk_notes.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(9) & """"
            x = x + 1
        end if
        
        if chk_computerserialno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(23) & """"
            x = x + 1
        end if
        
        arrTemp = GetComputerInfo(arrData(9))
        if IsArray(arrTemp) then
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & GetOUPath(replace(arrTemp(0),"""","")) & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(1),"""","") & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(2),"""","") & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(4),"""","") & """"
                x = x + 1
            end if
	 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(3),"""","") & """"
                x = x + 1
            end if
 
        else
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
        end if
        
        if chk_mobileno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(10) & """"
            x = x + 1
        end if
        
        if chk_company.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(11) & """"
            x = x + 1
        end if
        
        if chk_address.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(12) & """"
            x = x + 1
        end if
        
        if chk_city.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(13) & """"
            x = x + 1
        end if
        
        if chk_state.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(14) & """"
            x = x + 1
        end if
        
        if chk_zipcode.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(15) & """"
            x = x + 1
        end if
        
        if chk_country.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(16) & """"
            x = x + 1
        end if
        
        if chk_homephone.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(17) & """"
            x = x + 1
        end if
        
        if chk_manager.Checked then
            ReDim Preserve arrFileData(x)
            if arrData(18) <> "" then
                arrFileData(x) = """" & mid(arrData(18),4,instr(arrData(18),",")-4) & """"
            else
                arrFileData(x) = """" & """"
            end if
            x = x + 1
        end if
        
        if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
                
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
                
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
                
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = ""
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & str_subordinates & """"
                x = x + 1
            next
        end if
        
        if chk_whencreated.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(19) & """"
            x = x + 1
        end if
        
        if chk_oupathuser.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & GetOUPath(arrData(21)) & """"
            x = x + 1
        end if
        
        if chk_lastlogintimestamp.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(22) & """"
            x = x + 1
        end if
        
        if chk_groupmembership.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & ReportGroupMemberShipList(arrData(21), arrData(27)) & """"
            x = x + 1
        end if
 
        if CSVorTABLE <> "" then
            strFileData = strFileData & "<tr>"
            for n = 0 to UBound(arrFileData)-1
                strEntry = replace(arrFileData(n),"""","")
                if strEntry = "" then strEntry = "&nbsp;"
                strFileData = strFileData & "<td valign=""top"" align=""left"">" & strEntry & "</td>"
            next
            strFileData = strFileData & "</tr>" & vbCRLF
        else
            strFileData = strFileData & Join(arrFileData,",") & vbCRLF
        end if
    Next
    PopulateTableForCSV = strFileData
End Function 
 
Sub RunScript
      on error resume next
      Dim oDLG
      Set oDLG=CreateObject("MSComDlg.CommonDialog")
      if err.number > 0 then
          err.clear
          oDLG = window.prompt("Please enter the path and file name to save.", "D:\HTA-Result-Set.csv")
              if oDLG <> "" then
                  strAnswer = oDLG
              End If
      else
          With oDLG
              .DialogTitle = "Save As"
              .Filter="CSV File|*.csv"
              .MaxFileSize = 255
              .ShowSave
              If .FileName <> "" Then
                  strAnswer = .FileName
              End If
          End With
      end if
      Set oDLG=Nothing
 
      If IsNull(strAnswer) or strAnswer = "" Then
        'Do nothing
      Else
        if globalstrSearchBtnPush <> "" then
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            end if
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write CreateHeaderRow("") & vbCRLF
            objFile.Write PopulateTableForCSV("")
            objFile.Close
            MsgBox "Saved."
        else
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            Else
                ' do nothing
            end if
 
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write """Security Groups""" & VbCrLf
            For Each objOption in lst_groupnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Write """Distribution Groups""" & VbCrLf
            For Each objOption in lst_dgnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Close
            MsgBox "Saved."
        End if
      End If
End Sub
 
Sub Email_This_Record
 
        ShowDialogTo
        ShowDialogCC
   
        ConvertNamesToEmailAddresses
	
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	
        if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & txt_seatno.value & "<br>" & vbCRLF
	else
		str_seatno      = ""
	end if
 
        if chk_replacementseatno.Checked then
		str_replacementseatno      = "<b>These are the replacement details</b><br><b>Seat No: </b>" & txt_replacementseatno.value & "<br>" & vbCRLF
	else
		str_replacementseatno      = ""
	end if
 
	if chk_building.Checked then
		str_building    = "<b>Building: </b>" & txt_building.value &  "<br>" & vbCRLF
	else
		str_building    = ""
	end if
 
	if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & txt_extensionno.value &  "<br>" & vbCRLF
	else
		str_extensionno = ""
	end if
 
	if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & txt_empid.value &  "<br>" & vbCRLF
	else
		str_empid       = ""
	end if
 
	if chk_department.Checked then
		str_department  = "<b>Department: </b>" & txt_department.value &  "<br>" & vbCRLF
	else
		str_department  = ""
	end if
 
	if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & txt_designation.value &  "<br>" & vbCRLF
	else
		str_designation = ""
	end if
 
	if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & txt_name.value &  "<br>" & vbCRLF
	else
		str_name        = ""
	end if
 
	if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & txt_loginname.value &  "<br>" & vbCRLF
	else
		str_loginname   = ""
	end if
 
	if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & txt_email.value &  "<br>" & vbCRLF
	else
		str_email       = ""
	end if
 
	if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & txt_mailboxsize.value &  "<br>" & vbCRLF
	else
		str_mailboxsize       = ""
	end if
 
	if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & txt_mailboxstore.value &  "<br>" & vbCRLF
	else
		str_mailboxstore       = ""
	end if
 
	if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & txt_notes.value &  "<br>" & vbCRLF
	else
		str_notes       = ""
	end if
 
	if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & txt_computerserialno.value &  "<br>" & vbCRLF
	else
		str_computerserialno       = ""
	end if
 
	if chk_replacedmachine.Checked then
		str_replacedmachine       = "<b>These are the replacement details</b><br><b>Machine Name: </b>" & txt_replacedmachine.value &  "<br>" & vbCRLF
	else
		str_replacedmachine       = ""
	end if
 
	if chk_replacedcomputerserialno.Checked then
		str_replacedcomputerserialno       = "<b>Replaced Serial No: </b>" & txt_replacedcomputerserialno.value &  "<br>" & vbCRLF
	else
		str_replacedcomputerserialno       = ""
	end if
 
 
        arrTemp = GetComputerInfo(arrData(9))
 	if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & txt_oupathcomputer.value &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & txt_computeros.value &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & txt_computerservicepack.value &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & txt_computerdescription.value &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & txt_computercreated.value &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	end if
 
	if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & txt_mobileno.value &  "<br>" & vbCRLF
	else
		str_mobileno    = ""
	end if
 
	if chk_company.Checked then
		str_company     = "<b>Company: </b>" & txt_company.value &  "<br>" & vbCRLF
	else
		str_company     = ""
	end if
 
	if chk_address.Checked then
		str_address     = "<b>Address: </b>" & txt_address.value &  "<br>" & vbCRLF
	else
		str_address     = ""
	end if
 
	if chk_city.Checked then
		str_city        = "<b>City: </b>" & txt_city.value &  "<br>" & vbCRLF
	else
		str_city        = ""
	end if
 
	if chk_state.Checked then
		str_state       = "<b>State: </b>" & txt_state.value &  "<br>" & vbCRLF
	else
		str_state       = ""
	end if
 
	if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & txt_zipcode.value &  "<br>" & vbCRLF
	else
		str_zipcode     = ""
	end if
 
	if chk_country.Checked then
		str_country     = "<b>Country: </b>" & txt_country.value &  "<br>" & vbCRLF
	else
		str_country     = ""
	end if
 
	if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & txt_homephone.value &  "<br>" & vbCRLF
	else
		str_homephone   = ""
	end if
 
	if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
	else
		str_manager   = ""
	end if
 
	if chk_subordinates.Checked then
            str_subordinates = "<b>Subordinates: </b>"
            boolFoundFirst = False
            str_subordinates = ""
            For Each objOption in lst_subordinates.Options
                if boolFoundFirst then
                    str_subordinates = str_subordinates & ", " & objOption.Text
                else
                    boolFoundFirst = True
                    str_subordinates = str_subordinates & objOption.Text
                end if
            Next
            str_subordinates = str_subordinates &  "<br>" & vbCRLF
	else
            str_subordinates = ""
	end if
  
	if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & txt_whencreated.value &  "<br>" & vbCRLF
	else
		str_whencreated = ""
	end if
  
	if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & txt_oupathuser.value &  "<br>" & vbCRLF
	else
		str_oupathuser       = ""
	end if
  
	if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & txt_lastlogintimestamp.value &  "<br>" & vbCRLF
	else
		str_lastlogintimestamp       = ""
	end if
 
	if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
	else
		str_groupmembership       = ""
	end if
 
        str_message = str_seatno & _
            str_replacementseatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_replacedmachine & _
            str_replacedcomputerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership
 
      if trim(txt_EmailSubject.value) = "" then
          strEmailSubject = "Active Directory Detail Report"
      else
          strEmailSubject = trim(txt_EmailSubject.value)
      end if
 
        Set objMessage = CreateObject("CDO.Message")
        objMessage.From = strEmailFrom
        objMessage.To = strEmailTo
        objMessage.CC = strEmailCC
        objMessage.BCC = strEmailBCC
        objMessage.Subject = strEmailSubject
        objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
        objMessage.Configuration.Fields.Update
        objMessage.Send
 
        MsgBox "An email has been sent"
 
End Sub
 
Sub Email_All_Records
 
    ShowDialogTo
    ShowDialogCC
   
    ConvertNamesToEmailAddresses
 
    str_message = ""
    if boolTableReports then
        str_message = str_message & "<table width=""100%"" border=""1"">" & vbCRLF
        str_message = str_message & CreateHeaderRow("Table") & vbCRLF
        str_message = str_message & PopulateTableForCSV("Table") & vbCRLF
        str_message = str_message & "</table>" & vbCRLF
    else
        for n = 0 to UBound(arrRows)
	    arrData = Split(arrRows(n), "|TD|")
 
            if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & arrData(0) &  "<br>" & vbCRLF
	    else
		str_seatno      = ""
            end if
 
            if chk_building.Checked then
		str_building    = "<b>Building: </b>" & arrData(1) &  "<br>" & vbCRLF
            else
		str_building    = ""
            end if
 
            if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & arrData(2) &  "<br>" & vbCRLF
            else
		str_extensionno = ""
            end if
 
            if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & arrData(3) &  "<br>" & vbCRLF
            else
		str_empid       = ""
            end if
 
            if chk_department.Checked then
		str_department  = "<b>Department: </b>" & arrData(4) &  "<br>" & vbCRLF
            else
		str_department  = ""
            end if
 
            if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & arrData(5) &  "<br>" & vbCRLF
            else
		str_designation = ""
            end if
 
            if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & arrData(6) &  "<br>" & vbCRLF
            else
		str_name        = ""
            end if
 
            if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & arrData(7) &  "<br>" & vbCRLF
            else
		str_loginname   = ""
            end if
 
            if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & arrData(8) &  "<br>" & vbCRLF
            else
		str_email       = ""
            end if
 
            if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & arrData(25) &  "<br>" & vbCRLF
            else
		str_mailboxsize       = ""
            end if
 
            if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & arrData(26) &  "<br>" & vbCRLF
            else
		str_mailboxstore       = ""
            end if
 
            if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & arrData(9) &  "<br>" & vbCRLF
            else
		str_notes       = ""
            end if
 
            if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & arrData(23) &  "<br>" & vbCRLF
            else
		str_computerserialno       = ""
            end if
 
            arrTemp = GetComputerInfo(arrData(9))
            if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & GetOUPath(replace(arrTemp(0),"""","")) &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & replace(arrTemp(1),"""","") &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & replace(arrTemp(2),"""","") &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & replace(arrTemp(4),"""","") &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & replace(arrTemp(3),"""","") &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            end if
 
            if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & arrData(10) &  "<br>" & vbCRLF
            else
		str_mobileno    = ""
            end if
 
            if chk_company.Checked then
		str_company     = "<b>Company: </b>" & arrData(11) &  "<br>" & vbCRLF
            else
		str_company     = ""
            end if
 
            if chk_address.Checked then
		str_address     = "<b>Address: </b>" & arrData(12) &  "<br>" & vbCRLF
            else
		str_address     = ""
            end if
 
            if chk_city.Checked then
		str_city        = "<b>City: </b>" & arrData(13) &  "<br>" & vbCRLF
            else
		str_city        = ""
            end if
 
            if chk_state.Checked then
		str_state       = "<b>State: </b>" & arrData(14) &  "<br>" & vbCRLF
            else
		str_state       = ""
            end if
 
            if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & arrData(15) &  "<br>" & vbCRLF
            else
		str_zipcode     = ""
            end if
 
            if chk_country.Checked then
		str_country     = "<b>Country: </b>" & arrData(16) &  "<br>" & vbCRLF
            else
		str_country     = ""
            end if
 
            if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & arrData(17) &  "<br>" & vbCRLF
            else
		str_homephone   = ""
            end if
 
            if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
            else
		str_manager   = ""
            end if
 
            if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
   
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
    
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = "<b>Subordinates: </b>"
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                str_subordinates = str_subordinates &  "<br>" & vbCRLF
            next
            else
		str_subordinates = ""
            end if
 
            if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & arrData(19) &  "<br>" & vbCRLF
            else
		str_whencreated = ""
            end if
    
            if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & GetOUPath(arrData(21)) &  "<br>" & vbCRLF
            else
		str_oupathuser       = ""
            end if
    
            if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & arrData(22) &  "<br>" & vbCRLF
            else
		str_lastlogintimestamp       = ""
            end if
  
 
            if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
            else
		str_groupmembership       = ""
            end if
 
            str_message = str_message & _
            str_seatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership & VbCrLf & "<br><hr><br><br>" & vbCRLF
        next
    end if
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom 
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
    objMessage.Configuration.Fields.Update
    objMessage.Send
    
    MsgBox "An email has been sent"
    
End Sub
 
Sub Email_As_Attachment
    
    ShowDialogTo
    ShowDialogCC
    
    ConvertNamesToEmailAddresses
    
    strAnswer = fTemp & "\HTAResults.csv"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(strAnswer) = True Then
        objFSO.DeleteFile strAnswer, True
    end if
    Set objFile = objFSO.CreateTextFile(strAnswer, True)
    objFile.Write CreateHeaderRow("") & vbCRLF
    objFile.Write PopulateTableForCSV("")
    objFile.Close
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.TextBody = trim(txt_EmailBody.value) & vbCRLF & vbCRLF
    
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    
    objMessage.Configuration.Fields.Update
    objMessage.AddAttachment strAnswer
    objMessage.Send
    
    MsgBox "An email has been sent"
    objFSO.DeleteFile strAnswer, True
    
End Sub
 
Sub SelectAllCheck
	If chk_selectall.Checked then
		CheckAllBoxes
                TestToSeeWhatLinesAreHidden
	else
		UnCheckAllBoxes
	end if
End Sub
 
Sub UnCheckAllBoxes
	chk_selectall.Checked = False
	chk_seatno.Checked = False
	chk_replacementseatno.Checked = False
	chk_building.Checked = False
	chk_extensionno.Checked = False
	chk_seatno.Checked = False
	chk_empid.Checked = False
	chk_department.Checked = False
	chk_designation.Checked = False
	chk_name.Checked = False
	chk_loginname.Checked = False
	chk_email.Checked = False
	chk_mailboxsize.Checked = False
	chk_mailboxstore.Checked = False
	chk_notes.Checked = False
	chk_computerserialno.Checked = False
	chk_replacedmachine.Checked = False
	chk_replacedcomputerserialno.Checked = False
	chk_oupathcomputer.Checked = False
	chk_computeros.Checked = False
	chk_computerdescription.Checked = False
	chk_computercreated.Checked = False
	chk_mobileno.Checked = False
	chk_company.Checked = False
	chk_address.Checked = False
	chk_city.Checked = False
	chk_state.Checked = False
	chk_zipcode.Checked = False
	chk_country.Checked = False
	chk_homephone.Checked = False
	chk_manager.Checked = False
	chk_whencreated.Checked = False
	chk_oupathuser.Checked = False
	chk_lastlogintimestamp.Checked = False
	chk_groupmembership.Checked = False
	chk_dgmembership.Checked = False
	chk_managerlist.Checked = False
	chk_subordinates.Checked = False
End Sub
 
Sub CheckAllBoxes
	chk_selectall.Checked = True
	chk_seatno.Checked = True
	chk_replacementseatno.Checked = True
	chk_building.Checked = True
	chk_extensionno.Checked = True
	chk_empid.Checked = True
	chk_department.Checked = True
	chk_designation.Checked = True
	chk_name.Checked = True
	chk_loginname.Checked = True
	chk_email.Checked = True
	chk_mailboxsize.Checked = True
	chk_mailboxstore.Checked = True
	chk_notes.Checked = True
	chk_computerserialno.Checked = True
	chk_replacedmachine.Checked = True
	chk_replacedcomputerserialno.Checked = True
	chk_oupathcomputer.Checked = True
	chk_computeros.Checked = True
	chk_computerdescription.Checked = True
	chk_computercreated.Checked = True
	chk_mobileno.Checked = True
	chk_company.Checked = True
	chk_address.Checked = True
	chk_city.Checked = True
	chk_state.Checked = True
	chk_zipcode.Checked = True
	chk_country.Checked = True
	chk_homephone.Checked = True
	chk_manager.Checked = True
	chk_whencreated.Checked = True
	chk_oupathuser.Checked = True
	chk_lastlogintimestamp.Checked = True
	chk_groupmembership.Checked = True
	chk_dgmembership.Checked = True
	chk_managerlist.Checked = True
	chk_subordinates.Checked = True
End Sub
 
Function GetUsersEmailAddress
	Set oNet = CreateObject("WScript.NetWork")
	sSearchField = "(samAccountName=*" & oNet.UserName & "*)"
	Set objRootDSE = GetObject("LDAP://RootDSE")
	sDNSDomain = objRootDSE.Get("defaultNamingContext")
	sBase = "<LDAP://" & sDNSDomain & ">"
	sFilter = "(&(objectCategory=person)(objectClass=user)" & sSearchField & ")"
	sAttributes = "cn,samAccountName,mail"
	sQuery = sBase & ";" & sFilter & ";" & sAttributes & ";subtree"
	Set aCommand = CreateObject("ADODB.Command")
	Set aConnection = CreateObject("ADODB.Connection")
	aConnection.Provider = "ADsDSOObject"
	aConnection.Open "Active Directory Provider"
	aCommand.ActiveConnection = aConnection
	aCommand.CommandText = sQuery
	aCommand.Properties("Page Size") = 100
	aCommand.Properties("Timeout") = 30
	aCommand.Properties("Cache Results") = False
	Set aRecordset = aCommand.Execute
 
	GetUsersEmailAddress = aRecordset.Fields("cn").Value
 
End Function
 
Sub ShowDialogCC
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailCC.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailCC.Value = strValidEmail
End Sub
 
Sub ShowDialogTo
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailTo.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailTo.Value = strValidEmail
End Sub
 
Sub ShowDialogFrom
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailFrom.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailFrom.Value = strValidEmail
End Sub
 
Sub FillGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    on error resume next
    For Each objOption in lst_groupnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_dgnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
 
    ' This section is to pull group membership names
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
        strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
        strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
 
        if strLastGroupDN <> strdistinguishedName then
            Select Case strGroupType
                Case "[GDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[LDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[UDG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case "[GSG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[LSG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[USG]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case "[Unknown]"
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
            End Select
            strLastGroupDN = strdistinguishedName
        End if
        GroupMembershipDB.MoveNext
    Loop
    
    ' This section is to pull subordinate names
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoConnection = CreateObject("ADODB.Connection")
    Set adoCommand = CreateObject("ADODB.Command")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    Set adoCommand.ActiveConnection = adoConnection
 
    strSearchField = "(manager=" & usersDistinguishedname & ")"
    strBase = "<LDAP://" & strDNSDomain & ">"
    strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
    ' Comma delimited list of attribute values to retrieve.
    strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
    
    ' Construct the LDAP syntax query.
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
 
    ' Run the query.
    Set adoRecordset = adoCommand.Execute
 
    Do Until adoRecordset.EOF
        set newOption = document.createElement("OPTION")
        newOption.Text = adoRecordset.Fields("cn").Value & " (" & GetSubordinateNumbers(adoRecordset.Fields("distinguishedName").Value) & ")"
        newOption.Value = adoRecordset.Fields("samAccountName").Value & ";" & adoRecordset.Fields("distinguishedName").Value
        lst_subordinates.Add newOption
        adoRecordset.MoveNext
        intsubordinates = intsubordinates + 1
    Loop
    
    span_groupmembership.InnerHTML = "(" & intGroupMembership & ")"
    span_dgmembership.InnerHTML    = "(" & intdgmembership & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Function ReportGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        if strLastGroupDN <> strdistinguishedName then
            strGroupType  = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName     = GroupMembershipDB.Fields.Item("samaccountname").Value
            strValue      = strValue & strNTName & " " & strGroupType & ";"
            strLastGroupDN = strdistinguishedName
            GroupMembershipDB.MoveNext
        End if
    Loop
    strValue = mid(strValue,1,len(strValue)-1)
    ReportGroupMembershipList = strValue
End Function
 
Function GetManagerDN(Manager)
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    
    strBase = "<LDAP://" & strDNSDomain & ">"
    
    strFilter = "(&(objectCategory=person)(objectClass=user)(cn=*" & Manager & "*))"
    
    strAttributes = "distinguishedName,CN"
    
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    
    Set adoRecordset = CreateObject("ADODB.Recordset")
    adoRecordset.CursorLocation = 3
    adoRecordset.Sort = "distinguishedname"
    adoRecordset.Open strQuery, adoConnection, , , 1
    strresults = ""
    boolResultsFound = False
    Do Until adoRecordset.EOF
        strDN = adoRecordset.Fields("distinguishedName").Value
        sResults = sResults & "(manager=" & strDN & ")"
        boolResultsFound = True
        adoRecordset.MoveNext
    Loop
    if boolResultsFound then
        sResults = "(|" & sResults & ")"
    end if
    GetManagerDN = sResults
End Function
 
Sub FillGroupList
    For Each objOption in lst_groupnames.Options
        objOption.RemoveNode
    Next
 
    For Each objOption in lst_dgnames.Options
        objOption.RemoveNode
    Next
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
    
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(objectCategory=group)"
        strAttributes = "sAMAccountName,primaryGroupToken,distinguishedName,samaccounttype,member"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "distinguishedname"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intNumberOfMembers = 0
            strNTName = adoRecordset.Fields("sAMAccountName").Value
            strPrimary = adoRecordset.Fields("primaryGroupToken").Value
            strdistinguishedName = adoRecordset.Fields("distinguishedName").Value
            strGroupType = GetSAMAccountType(adoRecordset.Fields("samaccounttype").Value)
            if NOT IsNull(adoRecordset.Fields("member").Value) then
                for each strMember in adoRecordset.Fields("member").Value
                    GroupMembershipDB.AddNew
                    GroupMembershipDB("sAMAccountName")          = strNTName
                    GroupMembershipDB("primaryGroupToken")       = strPrimary
                    GroupMembershipDB("distinguishedName")       = strdistinguishedName
                    GroupMembershipDB("samaccounttype")          = strGroupType
                    GroupMembershipDB("MemberDistinguishedName") = strMember
                    GroupMembershipDB.Update
                    intNumberOfMembers = intNumberOfMembers + 1
                next
            else
                GroupMembershipDB.AddNew
                GroupMembershipDB("sAMAccountName")          = strNTName
                GroupMembershipDB("primaryGroupToken")       = strPrimary
                GroupMembershipDB("distinguishedName")       = strdistinguishedName
                GroupMembershipDB("samaccounttype")          = strGroupType
                GroupMembershipDB("MemberDistinguishedName") = ""
                GroupMembershipDB.Update
            End if
            if NOT dicGroupNumbers.Exists(strdistinguishedName) then
                dicGroupNumbers.Add strdistinguishedName, intNumberOfMembers
                if strPrimary = 513 then
                    GetUsersWithPrimaryGroupID 513, strdistinguishedName
                    intNumberOfMembers = dicGroupNumbers.Item(strdistinguishedName)
                end if
            end if
            Select Case adoRecordset.Fields("samaccounttype").Value
                Case 2,268435457,4,536870913,8,268435457
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_dgnames.Add newOption
                    intdgmembership = intdgmembership + 1
                Case -2147483646,268435456,-2147483644,536870912,-2147483640,268435456
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
                Case Else
                    set newOption = document.createElement("OPTION")
                    newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                    newOption.Value = strPrimary & ";" & strdistinguishedName
                    lst_groupnames.Add newOption
                    intGroupMembership = intGroupMembership + 1
            End Select
            
            adoRecordset.MoveNext
        Loop
    next
    
    span_groupmembership.InnerHTML = "(" & intGroupMembership & ")"
    span_dgmembership.InnerHTML    = "(" & intdgmembership & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Sub FillManagerList
    For Each objOption in lst_managerlist.Options
        objOption.RemoveNode
    Next
    intManagers = 0
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=*))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            strManager = adoRecordset.Fields("manager").Value
            if dicManagerList.Exists(strManager) then
                dicManagerList.Item(strManager) = dicManagerList.Item(strManager) + 1
            else
                dicManagerList.Add strManager, 1
                intManagers = intManagers + 1
            End if
            adoRecordset.MoveNext
        Loop
    next
    for each Manager in dicManagerList
        set newOption = document.createElement("OPTION")
        newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
        newOption.Value = Manager
        lst_managerlist.Add newOption
    next
    span_managerlist.InnerHTML = "(" & intManagers & ")"
End Sub
 
Sub PopulateManagerList
    For Each objOption in lst_managerlist.Options
        objOption.RemoveNode
    Next
    intManagers = 0
    for each Manager in dicManagerList
        set newOption = document.createElement("OPTION")
        newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
        newOption.Value = Manager
        lst_managerlist.Add newOption
        intManagers = intManagers + 1
    next
    span_managerlist.InnerHTML = "(" & intManagers & ")"
End Sub
 
Function GetSubordinateNumbers(manager)
    intSubordinates = 0
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=" & manager & "))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intSubordinates = intSubordinates + 1
            adoRecordset.MoveNext
        Loop
    next
    GetSubordinateNumbers = intSubordinates
End FUnction
 
Function GetSAMAccountType(SAMAccountType)
    Select Case SAMAccountType
        Case 2, 268435457
            GetSAMAccountType = "[GDG]" 'This is a global distribution group
        Case 4, 536870913
            GetSAMAccountType = "[LDG]" 'This is a domain local distribution group
        Case 8, 268435457
            GetSAMAccountType = "[UDG]" 'This is a universal distribution group
        Case -2147483646, 268435456
            GetSAMAccountType = "[GSG]" 'This is a global security group
        Case -2147483644, 536870912
            GetSAMAccountType = "[LSG]" 'This is a domain local security group
        Case -2147483640, 268435456
            GetSAMAccountType = "[USG]" 'This is a universal security group
        Case Else
            GetSAMAccountType = "[Unknown]" 'This is an unknown group type
    End Select
End Function
 
Sub GetUsersWithPrimaryGroupID(PrimaryGroupID,distinguishedName)
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    strSearchField = "(primaryGroupID=" & PrimaryGroupID & ")"
    for each strDomain in arrDomainNames
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
        strAttributes = "cn,primaryGroupID"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 100
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        Set adoRecordset = adoCommand.Execute
        If Not adoRecordset.EOF Then
            Do Until adoRecordset.EOF
                n = n + 1
                adoRecordset.movenext
            Loop
        End If
    next
    dicGroupNumbers.Item(distinguishedName) = n
End Sub
 
Sub FillSubjectList
    For Each objOption in txt_EmailSubject.Options
        objOption.RemoveNode
    Next
    For each strSubjectlineText in arrSubjectText
        set newOption = document.createElement("OPTION")
        newOption.Text = strSubjectlineText
        newOption.Value = strSubjectlineText
        txt_EmailSubject.Add newOption
    Next
End Sub
 
Sub ConvertNamesToEmailAddresses
    txt_EmailToHidden.Value = GetEmailAddresses(txt_EmailTo.Value)
    txt_EmailCCHidden.Value = GetEmailAddresses(txt_EmailCC.Value)
    strEmailTo = txt_EmailToHidden.Value
End Sub
 
Function GetEmailAddresses(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(names,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("mail").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
        end if
    next
    GetEmailAddresses = strValidEmail
End Function
 
Function GetOUPath(OU)
    strOU = ""
    strFQDN = ""
    boolFoundMatch = False
    arrValues = split(OU,",")
    for each strValue in arrValues
        if instr(strValue,"OU=") then
            strOU = strOU & replace(strValue,"OU=","") & "\"
        end if
        if instr(strValue,"DC=") then
            strFQDN = strFQDN & replace(strValue,"DC=","") & "."
        end if
        if instr(strValue,"CN=") then
            if boolFoundMatch then
                strCN = strCN & replace(strValue,"CN=","") & "\"
            else
                'Skip the first match - this is always the user name
                boolFoundMatch = True
            end if
        end if
    next
    if strFQDN <> "" then
        strFQDN = left(strFQDN,len(strFQDN)-1)
        if strOU <> "" then
            strOU = left(strOU,len(strOU)-1)
        else
            'strOU = "{object not found in any OU}"
            if strCN <> "" then
                strOU = left(strCN,len(strCN)-1)
            end if
        end if
        GetOUPath = (Split(strOU,"\")(0))
    else
        GetOUPath = ""
    end if
End Function
 
Function GetComputerInfo(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidComputer = ""
 
    strResolve = trim(names)
 
    if strResolve <> "" then
        Set objRoot = GetObject("LDAP://rootDSE")
        strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
        Set objConnection = CreateObject("ADODB.Connection")
        Set objCommand = CreateObject("ADODB.Command")
 
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open "Active Directory Provider"
 
        Set objCommand.ActiveConnection = objConnection
        objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _
        "(cn=" & strResolve & "));cn,samAccountName,distinguishedName,operatingsystem,operatingsystemservicepack,whencreated,description;subtree"
 
        objCommand.Properties("Page Size") = 1000
        objCommand.Properties("Timeout") = 90
        objCommand.Properties("Cache Results") = False
    
        Set objRecordSet1 = objCommand.Execute
 
        While Not objRecordSet1.EOF
 
            if IsNull(objRecordSet1.Fields("distinguishedName").Value) then
                sDN = ""
            else
                sDN = replace(objRecordSet1.Fields("distinguishedName").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystem").Value) then
                sOS = ""
            else
                sOS = replace(objRecordSet1.Fields("operatingsystem").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystemservicepack").Value) then
                sSP = ""
            else
                sSP = replace(objRecordSet1.Fields("operatingsystemservicepack").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("whencreated").Value) then
                sWC = ""
            else
                sWC = replace(objRecordSet1.Fields("whencreated").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("description").Value) then
                sDS = ""
            else
                sDS = join(objRecordSet1.Fields("description").Value)
                sDS = replace(sDS,vbCRLF,"")
            End if
 
            strValidComputer = Array("""" & sDN & """","""" & sOS & """","""" & sSP & """","""" & sWC & """","""" & sDS & """")
            objRecordSet1.MoveNext
        Wend 
    end if
 
    if isArray(strValidComputer) then
        GetComputerInfo = strValidComputer
    else
        GetComputerInfo = ""
    end if
End Function
 
Sub ShowSubMenu(Parent,Child)
    If Child.style.display="block" Then
        Parent.classname="Menuover"
        Child.style.display="none"
        Set LastChildMenu=Nothing
    Else
        Parent.classname="Menuin"
        Child.style.display="block"
        Set LastChildMenu=Child
    End If
    Set LastMenu=Parent
End Sub
 
Sub MenuOver(Parent,Child)
    If LastChildMenu is Nothing Then
        Parent.className="MenuOver"
    Else
        If LastMenu is Parent Then
            Parent.className="MenuIn"
        Else
            HideMenu
            ShowSubMenu Parent,Child
        End If
    End If
End Sub
 
Sub MenuOut(Menu)
    If LastChildMenu is Nothing Then Menu.className="MenuOut"
End Sub
 
Sub HideMenu
    If Not LastChildMenu is Nothing Then
        LastChildMenu.style.display="none"
        Set LastChildMenu=Nothing
        LastMenu.classname="Menuout"
    End If
End Sub
 
Sub SubMenuOver(Menu)
    Menu.className="SubMenuOver"
End Sub
 
Sub SubMenuOut(Menu)
    Menu.className="SubMenuOut"
End Sub
 
Sub SaveAs
    on error resume next
    Dim oDLG
    Set oDLG=CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to save.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            Save
        End If
    else
        With oDLG
            .DialogTitle = "Save As"
            .Filter="Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .ShowSave
            If .FileName <> "" Then
                FileName = .FileName
                Save
            End If
        End With
    end if
    Set oDLG=Nothing
    DisplayTitle
End Sub
 
Sub Save()
    Dim fso,f
    If FileName <> "" Then
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f = fso.CreateTextFile(FileName,True)
        
        'This is the text to get saved into the file
        with f
            .writeline "<root>"
            .writeline "<searchfield>" & globalStrSearchField & "</searchfield>"
            .writeline "<btnpush>" & globalStrSearchBtnPush & "</btnpush>"
            .writeline "<to>" & txt_EmailTo.value & "</to>"
            .writeline "<cc>" & txt_EmailCC.value & "</cc>"
            .writeline "<bcc>" & strEmailBCC & "</bcc>"
            .writeline "<subject>" & txt_EmailSubject.value & "</subject>"
            .writeline "<emailbody>" & txt_EmailBody.value & "</emailbody>"
            if chk_selectall.Checked then .writeline "<checkboxes>chk_selectall</checkboxes>"
            if chk_seatno.Checked then .writeline "<checkboxes>chk_seatno</checkboxes>"
            if chk_building.Checked then .writeline "<checkboxes>chk_building</checkboxes>"
            if chk_extensionno.Checked then .writeline "<checkboxes>chk_extensionno</checkboxes>"
            if chk_empid.Checked then .writeline "<checkboxes>chk_empid</checkboxes>"
            if chk_department.Checked then .writeline "<checkboxes>chk_department</checkboxes>"
            if chk_designation.Checked then  .writeline "<checkboxes>chk_designation</checkboxes>"
            if chk_name.Checked then .writeline "<checkboxes>chk_name</checkboxes>"
            if chk_loginname.Checked then .writeline "<checkboxes>chk_loginname</checkboxes>"
            if chk_email.Checked then .writeline "<checkboxes>chk_email</checkboxes>"
            if chk_mailboxsize.Checked then .writeline "<checkboxes>chk_mailboxsize</checkboxes>"
            if chk_mailboxstore.Checked then .writeline "<checkboxes>chk_mailboxstore</checkboxes>"
            if chk_notes.Checked then .writeline "<checkboxes>chk_notes</checkboxes>"
            if chk_computerserialno.Checked then .writeline "<checkboxes>chk_computerserialno</checkboxes>"
            if chk_replacedmachine.Checked then .writeline "<checkboxes>chk_replacedmachine</checkboxes>"
            if chk_replacedcomputerserialno.Checked then .writeline "<checkboxes>chk_replacedcomputerserialno</checkboxes>"
            if chk_oupathcomputer.Checked then .writeline "<checkboxes>chk_oupathcomputer</checkboxes>"
            if chk_computeros.Checked then .writeline "<checkboxes>chk_computeros</checkboxes>"
            if chk_computerdescription.Checked then .writeline "<checkboxes>chk_computerdescription</checkboxes>"
            if chk_computercreated.Checked then  .writeline "<checkboxes>chk_computercreated</checkboxes>"
            if chk_mobileno.Checked then  .writeline "<checkboxes>chk_mobileno</checkboxes>"
            if chk_company.Checked then .writeline "<checkboxes>chk_company</checkboxes>"
            if chk_address.Checked then  .writeline "<checkboxes>chk_address</checkboxes>"
            if chk_city.Checked then .writeline "<checkboxes>chk_city</checkboxes>"
            if chk_state.Checked then .writeline "<checkboxes>chk_state</checkboxes>"
            if chk_zipcode.Checked then .writeline "<checkboxes>chk_zipcode</checkboxes>"
            if chk_country.Checked then .writeline "<checkboxes>chk_country</checkboxes>"
            if chk_homephone.Checked then .writeline "<checkboxes>chk_homephone</checkboxes>"
            if chk_manager.Checked then .writeline "<checkboxes>chk_manager</checkboxes>"
            if chk_whencreated.Checked then .writeline "<checkboxes>chk_whencreated</checkboxes>"
            if chk_oupathuser.Checked then .writeline "<checkboxes>chk_oupathuser</checkboxes>"
            if chk_lastlogintimestamp.Checked then .writeline "<checkboxes>chk_lastlogintimestamp</checkboxes>"
            if chk_groupmembership.Checked then .writeline "<checkboxes>chk_groupmembership</checkboxes>"
            if chk_dgmembership.Checked then .writeline "<checkboxes>chk_dgmembership</checkboxes>"
            if chk_managerlist.Checked then .writeline "<checkboxes>chk_managerlist</checkboxes>"
            if chk_subordinates.Checked then .writeline "<checkboxes>chk_subordinates</checkboxes>"
            .writeline "</root>"
            .Close
        end with
        
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        XmlDom.async = False
        XmlDom.Load(FileName)
        xmlDom.Save(FileName)
        
        Set f = Nothing
        Set fso = Nothing
    Else
        SaveAs
    End If
End Sub
 
Sub OpenIt
    UnCheckAllBoxes
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    xmlDom.load(FileName)
    
    globalStrSearchField = xmlDom.getElementsByTagName("searchfield").item(0).text
    globalStrSearchBtnPush = xmlDom.getElementsByTagName("btnpush").item(0).text
    txt_EmailTo.value = xmlDom.getElementsByTagName("to").item(0).text
    txt_EmailCC.value = xmlDom.getElementsByTagName("cc").item(0).text
    strEmailBCC = xmlDom.getElementsByTagName("bcc").item(0).text
    txt_EmailSubject.value = xmlDom.getElementsByTagName("subject").item(0).text
    txt_EmailBody.value = xmlDom.getElementsByTagName("emailbody").item(0).text
    
    for n = 0 to xmlDom.getElementsByTagName("checkboxes").Length-1
        execute(xmlDom.getElementsByTagName("checkboxes").item(n).text & ".checked = True")
    next
    
    DisplayTitle
    
    Submit_Form "FileOpen"
End Sub
 
Sub Open()
    on error resume next
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            OpenIt
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                FileName = .FileName
                OpenIt
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub DisplayTitle
    If FileName="" Then
        document.Title="Default - " & oHTA.ApplicationName
    Else
        document.Title=FileName & " - " & oHTA.ApplicationName
    End If
End Sub
 
Sub ClickTheSpecialReportButton
    Submit_Form("Disabled")
End Sub
 
Sub SpecialReportNewUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("Main")
End Sub
 
Sub SpecialReportDisabledUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub SpecialReportDisabledUsersSomeDay
    Clear_Form ""
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    txt_whencreated.value = sRtn
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub GetChkProfiles 
    For Each objOption in lst_ChkProfiles.Options
        objOption.RemoveNode
    Next
    
    strAnswer = fAppData & "\profile.xml"
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If NOT objFSO.FileExists(strAnswer) Then
        'Create profile.xml
	Set f = objFSO.CreateTextFile(strAnswer,True)
        with f
            .writeline "<root>"
            .writeline "<profile val=""Default"">"
            .writeline "<checkboxes val=""chk_selectall"" />"
            .writeline "<checkboxes val=""chk_seatno"" />"
            .writeline "<checkboxes val=""chk_replacementseatno"" />"
            .writeline "<checkboxes val=""chk_building"" />"
            .writeline "<checkboxes val=""chk_extensionno"" />"
            .writeline "<checkboxes val=""chk_empid"" />"
            .writeline "<checkboxes val=""chk_department"" />"
            .writeline "<checkboxes val=""chk_designation"" />"
            .writeline "<checkboxes val=""chk_name"" />"
            .writeline "<checkboxes val=""chk_loginname"" />"
            .writeline "<checkboxes val=""chk_email"" />"
            .writeline "<checkboxes val=""chk_mailboxsize"" />"
            .writeline "<checkboxes val=""chk_mailboxstore"" />"
            .writeline "<checkboxes val=""chk_notes"" />"
            .writeline "<checkboxes val=""chk_computerserialno"" />"
            .writeline "<checkboxes val=""chk_replacedmachine"" />"
            .writeline "<checkboxes val=""chk_replacedcomputerserialno"" />"
            .writeline "<checkboxes val=""chk_oupathcomputer"" />"
            .writeline "<checkboxes val=""chk_computeros"" />"
            .writeline "<checkboxes val=""chk_computerdescription"" />"
            .writeline "<checkboxes val=""chk_computercreated"" />"
            .writeline "<checkboxes val=""chk_mobileno"" />"
            .writeline "<checkboxes val=""chk_company"" />"
            .writeline "<checkboxes val=""chk_address"" />"
            .writeline "<checkboxes val=""chk_city"" />"
            .writeline "<checkboxes val=""chk_state"" />"
            .writeline "<checkboxes val=""chk_zipcode"" />"
            .writeline "<checkboxes val=""chk_country"" />"
            .writeline "<checkboxes val=""chk_homephone"" />"
            .writeline "<checkboxes val=""chk_manager"" />"
            .writeline "<checkboxes val=""chk_whencreated"" />"
            .writeline "<checkboxes val=""chk_oupathuser"" />"
            .writeline "<checkboxes val=""chk_lastlogintimestamp"" />"
            .writeline "<checkboxes val=""chk_groupmembership"" />"
            .writeline "<checkboxes val=""chk_dgmembership"" />"
            .writeline "<checkboxes val=""chk_managerlist"" />"
            .writeline "<checkboxes val=""chk_subordinates"" />"
            .writeline "</profile>"
            .writeline "</root>"
            .Close
	end with
 
	Set xmlDom = CreateObject("Microsoft.XMLDOM")
	XmlDom.async = False
	XmlDom.Load(strAnswer)
	xmlDom.Save(strAnswer)
    End If
 
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile")
    
    for n = 0 to oNodes.length - 1
        set newOption = document.createElement("OPTION")
        newOption.Text = oNodes(n).selectSingleNode("@val").Text
        newOption.Value = oNodes(n).selectSingleNode("@val").Text
        lst_ChkProfiles.Add newOption
    next
 
    Set f = Nothing
    Set objFSO = Nothing
End Sub
 
Sub lst_chkprofiles_OnChange
 
    UnCheckAllBoxes
 
    strAnswer = fAppData & "\profile.xml"
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]/checkboxes")   
 
    For i = 0 To oNodes.length - 1
        execute(oNodes(i).selectSingleNode("@val").Text & ".Checked = True")
    Next
 
    TestToSeeWhatLinesAreHidden
End Sub
 
Sub DeleteFromCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        For Each objOption in lst_chkprofiles.Options
            If objOption.Value = lst_chkprofiles.Value Then
                objOption.RemoveNode
            End If
        Next
        msgbox "Checkbox profile deleted."
        lst_chkprofiles_OnChange
    else
        msgbox "You cannot delete the default profile."
    end if
End Sub
 
Sub ModifyCurrentCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        strProfileName = lst_chkprofiles.Value
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        
        Const ForReading = 1
        Const ForWriting = 2
     
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
     
        Do Until objFile.AtEndOfStream
            strLine = objFile.Readline
            strLine = Trim(strLine)
            If strLine <> "</root>" Then
                strContents = strContents & strLine & vbCrLf
            End If
        Loop
     
        objFile.Close
        
        Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
        
        with f
            .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
            if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
            if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
            if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
            if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
            if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
            if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
            if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
            if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
            if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
            if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
            if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
            if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
            if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
            if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
            if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
            if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
            if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
            if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
            if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
            if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
            if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
            if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
            if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
            if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
            if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
            if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
            if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
            if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
            if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
            if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
            if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
            if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
            if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
            if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
            if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
            if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
            if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
            .writeline vbTab & "</profile>"
            .writeline "</root>"
            .close
        end with
        
        msgbox "Checkbox profile modified."
    else
        msgbox "You cannot modify the default profile."
    end if
End Sub
 
Sub AddToCheckboxProfile
    strProfileName = window.prompt("Please enter a profile name.", "My profile name")
    strAnswer = fAppData & "\profile.xml"
 
    Const ForReading = 1
    Const ForWriting = 2
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
 
    Do Until objFile.AtEndOfStream
        strLine = objFile.Readline
        strLine = Trim(strLine)
        If strLine <> "</root>" Then
            strContents = strContents & strLine & vbCrLf
        End If
    Loop
 
    objFile.Close
    
    Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
    
    with f
        .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
	if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
	if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
        if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
	if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
	if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
	if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
	if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
	if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
	if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
	if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
	if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
	if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
	if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
	if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
	if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
	if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
	if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
	if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
	if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
	if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
	if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
	if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
	if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
	if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
	if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
	if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
	if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
	if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
	if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
	if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
	if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
	if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
	if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
	if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
	if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
	if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
	if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
	.writeline vbTab & "</profile>"
	.writeline "</root>"
        .close
    end with
 
    set newOption = document.createElement("OPTION")
    newOption.Text = strProfileName
    newOption.Value = strProfileName
    lst_ChkProfiles.Add newOption
 
    lst_ChkProfiles.Value = strProfileName
End Sub
 
Sub AddToQueryBuilder
	globalstrQueryBuilder = globalstrQueryBuilder & globalstrSearchField
	if NOT chk_qbrecorder.Checked then
		msgbox "The query has been added."
	end if
End Sub
 
Sub QueryBuilderRecorder
    if chk_qbrecorder.Checked then
        msgbox "Query Builder is now recording."
    else
        msgbox "Query Builder has stopped recording." & vbCrLf & "Click OK to view the combined query."
        RunQueryBuilder
    end if
End Sub
 
Sub ViewQueryBuilder
    if globalstrQueryBuilder <> "" then
        msgbox "(|" & globalstrQueryBuilder & ")"
    else
        msgbox "There are no stored queries to view."
    end if
End Sub
 
Sub RunQueryBuilder
    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
    globalstrSearchBtnPush = "FileOpen"
    Submit_Form "FileOpen"
End Sub
 
Sub ClearQueryBuilder
    globalstrQueryBuilder = ""
End Sub
 
Sub txt_EmailSubject_OnChange
    For i = 0 to (txt_EmailSubject.Options.Length - 1)
        If (txt_EmailSubject.Options(i).Selected) Then
            strEmailTo          = arrToSpecial(i)
            strEmailCC          = arrCCSpecial(i)
            strEmailBody        = arrBodySpecial(i)
            strCheckBoxProfile  = arrCheckBoxSpecial(i)
            txt_EmailTo.Value   = strEmailTo
            txt_EmailCC.Value   = strEmailCC
            txt_EmailBody.Value = strEmailBody
            For Each objOption in lst_chkprofiles.Options
                If objOption.Value = strCheckBoxProfile Then
                    objOption.Selected = True
                    lst_chkprofiles_OnChange
                End If
            Next
        End If
    Next
End Sub
 
Sub PingComputer(name)
    if name <> "" then
        strComuptername = trim(name)
        'Run PING command
        Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
        'Take ping reults and put into variable strPingResult 
        strPingResult = 0
        For Each oPingResult In objPingResults
            strPingResult = oPingResult.ResponseTime
            strIPAddress  = oPingResult.ProtocolAddress
        Next
        'Catch PINGS that do not have a result - typically this is for unreachable devices
        if IsEmpty(strPingResult) then
            strPingResult = 9999
        end if
        if IsNULL(strPingResult) then
            strPingResult = 9999
        end if
        ' Run ping again if first attempt fails
        if strPingResult = 9999 then
            'Run PING command
            Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
            'Take ping reults and put into variable strPingResult 
            strPingResult = 0
            For Each oPingResult In objPingResults
                strPingResult = oPingResult.ResponseTime
                strIPAddress  = oPingResult.ProtocolAddress
            Next
            'Catch PINGS that do not have a result - typically this is for unreachable devices
            if IsEmpty(strPingResult) then
                strPingResult = 9999
            end if
            if IsNULL(strPingResult) then
                strPingResult = 9999
            end if
        end if
        span_computerip.innerhtml = strIPAddress
        if strPingResult = 9999 then
            span_computeronline.innerhtml = "Offline"
        else
            span_computeronline.innerhtml = "Online"
        end if
    else
        span_computerip.innerhtml = " "
        span_computeronline.innerhtml = " "
    end if
End Sub
 
Sub bt2Go_onclick()
 
    '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, DENY, POS, NEG
    Dim objNetwork, objShell
 
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Write username for the user that needs to be enabled or disabled:'
    USR = InputBox("Username:", "Enable or Disable Active Directory User", _
    "Write Username Here")
     
    if USR = "" then
	exit sub
    End if
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** Declare NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate name into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
    '** Do LDAP bind to object:'
    Set objUser = GetObject("LDAP://" & strUserDN)
     
    '** Get full name:'
    strUS1 = Mid(strUserDN,4)
    strUS2 = Split(strUS1, ",")
    For i = LBound(strUS2) to UBound(strUS2)
        strNM = strUS2(i)
        Exit For
    Next
 
    '** If no error, enable or disable user:'
    If Err = 0 Then
        Const ADS_UF_ACCOUNTDISABLE = 2
        intUAC = objUser.Get("userAccountControl")
        objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
        objUser.SetInfo
        If intUAC AND ADS_UF_ACCOUNTDISABLE Then
            POS = 1
        Else
            NEG = 1
        End If
    Else
        objShell.Popup UCase(USR) & " was not found. Please try again.", _
        5, "Unknown Username", 48
        exit sub
    End If
 
    '** If no permission, give message:'
    If Err = "-2147024891" Then
        DENY = 1
        objShell.Popup "You can not enable or disable this user.", _
        5, "Permission Denied", 48
        exit sub
    End If
 
    '** If no error, show result:'
    If DENY <> 1 Then
        If POS = 1 Then
            MsgBox UCase(USR) & " were successfully enabled.", _
            64, "User enabled by " & strNM2
        End If
 
        If NEG = 1 Then
            MsgBox UCase(USR) & " were successfully disabled.", _
            64, "User disabled by " & strNM2
        End If
    End If
End Sub
 
Sub bt1Go_onclick()
     '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, EROR, ABS
    Dim objNetwork, objShell, objFSO
     
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Type username for the user that needs password change:'
    USR = InputBox("Username:", "Create Temporary Active Directory User Password", _
    "Write Username Here")
     
    if USR = "" then
        exit sub
    End if
 
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate username into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    If Err <> 0 Then
        ABS = 1
    End If
     
    '** Execute if object is found:'
    If ABS <> 1 Then
        strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
        '** Do LDAP bind to object:'
        Set objUser = GetObject("LDAP://" & strUserDN)
     
        '** Get full name:'
        strUS1 = Mid(strUserDN,4)
        strUS2 = Split(strUS1, ",")
        For i = LBound(strUS2) to UBound(strUS2)
            strNM = strUS2(i)
            Exit For
        Next
     
        '** Assign password and parameters:'
        If strNM <> "" Then
            TNP = "changeme" & Mid(objFSO.GetTempName,4,4)
            objUser.SetPassword TNP
            If Err <> 0 Then
                EROR = 1
            End If
            objUser.Put "pwdLastSet", 0
            objUser.IsAccountLocked = False
            objUser.SetInfo
        End If
     
        '** If no error, show new temporary password:'
        If EROR <> 1 Then
            MsgBox "New temporary password for " & UCase(USR) & " (" & strNM & "):" & _
            vbCrLf & vbCrLf & TNP & vbCrLf, 64, "New Password, configured by " & strNM2
        End If
 
    End If
 
    '** End if object not found:'
    If ABS = 1 Then
        MsgBox UCase(USR) & " was not found. Please try again.", _
        48, "Unknown Username"
    End If
 
    '** If no permission, give message:'
    If EROR = 1 Then
        MsgBox "You can not change password for this user.", _
        48, "Permission Denied"
    End If
 
End Sub 
 
Sub ImportFromExcel
    on error resume next
    boolEndofFile = False
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "D:\your-spreadsheet.xls")
        if oDLG <> "" then
            globalstrQueryBuilder = ""
            Set objExcel = CreateObject("Excel.Application")
            Set objWorkbook = objExcel.Workbooks.Open(oDLG)
            intRow = 2
            Do Until boolEndofFile
                'According to ticket Q__23804616, these are the fields that are in the spreadsheet;
                'Emp ID,Seat No,Email ID,Full Name, NT Login,Machine Name
                strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                    boolEndofFile = True
                else
                    if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                    if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                    if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                    if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                    if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                    if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                end if
                intRow = intRow + 1
            Loop
            objExcel.Quit
            globalstrQueryBuilder = strValue
	    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	    globalstrSearchBtnPush = "FileOpen"
	    Submit_Form "FileOpen"
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Excel Workbook|*.xls"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                globalstrQueryBuilder = ""
                Set objExcel = CreateObject("Excel.Application")
                Set objWorkbook = objExcel.Workbooks.Open(.FileName)
                intRow = 2
                Do Until boolEndofFile
                    strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                    strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                    strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                    strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                    strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                    strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                    if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                        boolEndofFile = True
                    else
                        if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                        if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                        if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                        if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                        if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                        if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                    end if
                    intRow = intRow + 1
                Loop
                objExcel.Quit
                globalstrQueryBuilder = strValue
	        globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	        globalstrSearchBtnPush = "FileOpen"
	        Submit_Form "FileOpen"
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub About_OnClick
    'Enter names as contibuters increase.
    msgbox vbCRLF & "User and Computer Account Control" & vbCRLF & vbCRLF & "Written for Sharatha and contributed by;" & vbCRLF & vbCRLF & vbtab & _
    """rejoinder""" & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab
End Sub
 
Sub RunHTA(NameOfHTA)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run NameOfHTA
End Sub
 
Sub allowpings
    if chk_allowpings.Checked then
        boolAllowPing = True
    else
        boolAllowPing = False
    end if
End Sub
 
Sub LookupLastLogin
    if chk_LookupLastLogin.Checked then
        boolLookupLastLogin = True
    else
        boolLookupLastLogin = False
    end if
End Sub
 
Sub TableReports
    if chk_TableReports.Checked then
        boolTableReports = True
    else
        boolTableReports = False
    end if
End Sub
 
Sub GetMailboxDetails
    on error resume next
    strExchangeServerQuery = "winmgmts://" & strEmailServer & "/root/cimv2/applications/exchange"
    set serverList = GetObject(strExchangeServerQuery).InstancesOf("ExchangeServerState")
    For each ExchangeServer in serverList
        strExchangeQuery = "winmgmts://" & ExchangeServer.Name & "/root/MicrosoftExchangeV2"
        strExchangeQuery = "winmgmts://" & strEmailServer & "/root/MicrosoftExchangeV2"
        Set objMailboxes = GetObject(strExchangeQuery).InstancesOf("Exchange_Mailbox")
        For each mailbox in objMailboxes
            MailboxList.AddNew
            MailboxList("legacyExchangeDN") = mailbox.LegacyDN
            MailboxList("mailboxsize") = Round(mailbox.Size / 1024)
            MailboxList.Update
        Next
    Next
    MailboxList.MoveFirst
End Sub
 
Sub MailboxSizeCompare
    oDLG = window.prompt("Enter the mailbox size limit in MB.", "1000")
    if IsNumeric(oDLG) then
        Submit_Form("MailboxSize:" & oDLG)
    end if
End Sub
 
Sub DoCal(elTarget)
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    Execute(elTarget & ".value = sRtn")
    Detect_Search_Field(elTarget)
End Sub
 
Function GetOUMembers(OU)
    strValue = ""
    on error resume next
    GroupMembershipDB.Filter = "MemberDistinguishedName LIKE '*OU=" & OU & "*'"
    GroupMembershipDB.Sort   = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    Do While Not GroupMembershipDB.EOF
        strValue = strValue & "(DistinguishedName=" & GroupMembershipDB.Fields.Item("MemberDistinguishedName").Value & ")"
        GroupMembershipDB.MoveNext
    Loop
    if err.number > 0 then
        GetOUMembers = "INVALID"
    else
        GetOUMembers = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForOSQuery(OS)
    strValue = ""
    strSearchField = "(operatingsystem=*" & OS & "*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForOSQuery = "INVALID"
    else
        GetComputersForOSQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForDateCreatedQuery(CreatedDate)
    strValue = ""
    strWhenCreated = Year(CreatedDate) & Right("0" & Month(CreatedDate), 2) & Right("0" & Day(CreatedDate), 2)
    strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForDateCreatedQuery = "INVALID"
    else
        GetComputersForDateCreatedQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersBasedOnOU(OU)
    strValue = ""
    
    strSearchField = "(distinguishedName=*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
            
    boolFoundRecords = False
            
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
                  
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
 
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,distinguishedName"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
 
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
                  
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                if InStr(adoRecordset.Fields("distinguishedName").Value,OU) > 0 then
                    strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                End if
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersBasedOnOU = "INVALID"
    else
        GetComputersBasedOnOU = "(|" & strValue & ")"
    End if
End Function
 
Sub txt_filtersecuritygroup_onKeyUP
    on error resume next
    if txt_filtersecuritygroup.Value <> "" then
        Detect_Search_Field "txt_filtersecuritygroup"
        For Each objOption in lst_groupnames.Options
            objOption.RemoveNode
        Next
        intGroupMembership = 0
        GroupMembershipDB.Filter = "samaccountname LIKE '*" & txt_filtersecuritygroup.Value & "*'"
        GroupMembershipDB.Sort = "SAMAccountName"
        GroupMembershipDB.MoveFirst
        strLastGroupDN = ""
        Do Until GroupMembershipDB.EOF
            strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
            strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
            strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
            intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
    
            if strLastGroupDN <> strdistinguishedName then
                Select Case strGroupType
                    Case "[GSG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_groupnames.Add newOption
                        intGroupMembership = intGroupMembership + 1
                    Case "[LSG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_groupnames.Add newOption
                        intGroupMembership = intGroupMembership + 1
                    Case "[USG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_groupnames.Add newOption
                        intGroupMembership = intGroupMembership + 1
                    Case "[Unknown]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_groupnames.Add newOption
                        intGroupMembership = intGroupMembership + 1
                End Select
                strLastGroupDN = strdistinguishedName
            End if
            GroupMembershipDB.MoveNext
        Loop
        span_GroupMembership.InnerHTML = "(" & intGroupMembership & ")"
    end if
End Sub
 
Sub txt_filterdgmembership_onKeyUP
    on error resume next
    if txt_filterdgmembership.Value <> "" then
        Detect_Search_Field "txt_filterdgmembership"
        For Each objOption in lst_dgnames.Options
            objOption.RemoveNode
        Next
        intdgmembership = 0
        GroupMembershipDB.Filter = "samaccountname LIKE '*" & txt_filterdgmembership.Value & "*'"
        GroupMembershipDB.Sort = "SAMAccountName"
        GroupMembershipDB.MoveFirst
        strLastGroupDN = ""
        Do Until GroupMembershipDB.EOF
            strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
            strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
            strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
            intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
    
            if strLastGroupDN <> strdistinguishedName then
                Select Case strGroupType
                    Case "[GDG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_dgnames.Add newOption
                        intdgmembership = intdgmembership + 1
                    Case "[LDG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_dgnames.Add newOption
                        intdgmembership = intdgmembership + 1
                    Case "[UDG]"
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName & " (" & intNumberOfMembers & ") " & strGroupType
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_dgnames.Add newOption
                        intdgmembership = intdgmembership + 1
                End Select
                strLastGroupDN = strdistinguishedName
            End if
            GroupMembershipDB.MoveNext
        Loop
        span_groupmembership.InnerHTML = "(" & intdgmembership & ")"
    end if
End Sub
 
Sub txt_filtermanagerlist_onKeyUP
    if txt_filtermanagerlist.Value <> "" then
        Detect_Search_Field "txt_filtermanagerlist"
        For Each objOption in lst_managerlist.Options
            objOption.RemoveNode
        Next
        intManagers = 0
        for each Manager in dicManagerList
            if InStr(UCase(Manager),UCase(txt_filtermanagerlist.Value)) then
                set newOption = document.createElement("OPTION")
                newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
                newOption.Value = Manager
                lst_managerlist.Add newOption
                intManagers = intManagers + 1
            end if
        next
        span_managerlist.InnerHTML = "(" & intManagers & ")"
    end if
End Sub
 
Function GetMailboxStore(MailboxStore)
    if MailboxStore <> "" OR NOT IsNull(MailboxStore) then
        arrMailboxStoreString = Split(MailboxStore,"CN=")
        GetMailboxStore = replace(arrMailboxStoreString(2),",","")
    else
        GetMailboxStore = ""
    End if
End Function
 
Sub FillDomainComputers
    For Each objOption in lst_domaincomputers.Options
        objOption.RemoveNode
    Next
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    strBase = "<LDAP://" & strDNSDomain & ">"
    strFilter = "(&(objectCategory=computer)(cn=*))"
    strAttributes = "CN,DistinguishedName"
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    Set adoRecordset = CreateObject("ADODB.Recordset")
    adoRecordset.CursorLocation = 3
    adoRecordset.Sort = "CN"
    adoRecordset.Open strQuery, adoConnection, , , 1
    strresults = ""
    boolResultsFound = False
    intDomainComputers = 0
    Do Until adoRecordset.EOF
        strCN = adoRecordset.Fields("CN").Value
        strDN = adoRecordset.Fields("DistinguishedName").Value
        
        DomainComputersDB.AddNew
        DomainComputersDB("CN") = strCN
        DomainComputersDB("DistinguishedName") = strDN
        DomainComputersDB.Update
        
        set newOption = document.createElement("OPTION")
        newOption.Text = strCN
        newOption.Value = strCN
        lst_domaincomputers.Add newOption
        intDomainComputers = intDomainComputers + 1
        adoRecordset.MoveNext
    Loop
    span_domaincomputers.InnerHTML = "(" & intDomainComputers & ")"
End Sub
 
Sub lst_domaincomputers_onDblClick
    For Each objOption in lst_domaincomputers.Options
        If objOption.Selected = True Then
            strComputer = objOption.Value
            txt_notes.Value = strComputer
            Detect_Search_Field "txt_notes"
            Submit_Form "Main"
        End If
    Next
End Sub
 
Sub txt_filterdomaincomputers_onKeyUP
    on error resume next
    if txt_filterdomaincomputers.Value <> "" then
        Detect_Search_Field "txt_filterdomaincomputers"
        For Each objOption in lst_domaincomputers.Options
            objOption.RemoveNode
        Next
        intDomainComputers = 0
        DomainComputersDB.Filter = "CN LIKE '*" & txt_filterdomaincomputers.Value & "*'"
        DomainComputersDB.Sort = "CN"
        DomainComputersDB.MoveFirst
        Do Until DomainComputersDB.EOF
            strCN = DomainComputersDB.Fields.Item("CN").Value
            set newOption = document.createElement("OPTION")
            newOption.Text = strCN
            newOption.Value = strCN
            lst_domaincomputers.Add newOption
            intDomainComputers = intDomainComputers + 1
            DomainComputersDB.MoveNext
        Loop
        span_domaincomputers.InnerHTML = "(" & intDomainComputers & ")"
    else
        populatedomaincomputers
    end if
End Sub
 
Sub populatedomaincomputers
    on error resume next
    For Each objOption in lst_domaincomputers.Options
        objOption.RemoveNode
    Next
    intDomainComputers = 0
    DomainComputersDB.Filter = ""
    DomainComputersDB.Sort = "CN"
    DomainComputersDB.MoveFirst
    Do Until DomainComputersDB.EOF
        strCN = DomainComputersDB.Fields.Item("CN").Value
        set newOption = document.createElement("OPTION")
        newOption.Text = strCN
        newOption.Value = strCN
        lst_domaincomputers.Add newOption
        intDomainComputers = intDomainComputers + 1
        DomainComputersDB.MoveNext
    Loop
    span_domaincomputers.InnerHTML = "(" & intDomainComputers & ")"
End Sub
 
Sub ResetComputerPassword
    if txt_notes.value <> "" then
        DomainComputersDB.Filter = "CN='" & txt_notes.value & "'"
        DomainComputersDB.MoveFirst
        strLDAP = "LDAP://" & DomainComputersDB.Fields.Item("distinguishedname").Value
        set objComputer = GetObject(strLDAP)
        objComputer.SetPassword txt_notes.value & "$"
    else
        msgbox "Please enter a valid computer name."
    End if
End Sub
 
</script>
 
<STYLE TYPE="text/css">
<!--
body		{background-color: menu;color: menutext;}
td		{font-family: MS Sans Serif;font-size: 8pt;}
input		{font-family: MS Sans Serif;font-size: 8pt;}
button		{font-family: MS Sans Serif;font-size: 8pt;}
option		{font-family: MS Sans Serif;font-size: 8pt;}
select		{font-family: MS Sans Serif;font-size: 8pt;}
.submenu	{position:absolute;top=35;
		background-color:Menu;
		border="1px outset";}
.MenuIn		{border:"1px inset";cursor:default;}
.Menuover	{border:"1px outset";cursor:default;}
.Menuout	{}
.Submenuover	{background-color:highlight;color:highlighttext;cursor:default;}
.Submenuout	{background-color:Menu;color:MenuText;cursor:default;}
.HideFromGUI	{display:none;}
 
-->
</STYLE>
<body>
<!-- Main menu -->
<TABLE id=MenuTable height=25><TR>
	<TD	onclick='ShowSubMenu Me,MyFileMenu'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> Query </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,MyEditMenu'
		onmouseover='MenuOver Me,MyEditMenu'
		onmouseout='MenuOut Me'> Reports </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,QueryBuilderMenu'
		onmouseover='MenuOver Me,QueryBuilderMenu'
		onmouseout='MenuOut Me'> Query&nbsp;Builder </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,ToolsMenu'
		onmouseover='MenuOver Me,ToolsMenu'
		onmouseout='MenuOut Me'> Tools </TD>
	<TD	>|</TD>
	<TD	> Checkbox&nbsp;Profile&nbsp;<select id="lst_chkprofiles" name="lst_chkprofiles">
 
	</select>
	</TD>
<!-- Main menu, Checkbox profile tools -->
	<TD	onclick='AddToCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [+]Add</TD>
	<TD	onclick='DeleteFromCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [-]Delete</TD>
	<TD	onclick='ModifyCurrentCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [!]Modify</TD>
	<TD	>|</TD>
	<TD	onclick='About_OnClick'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> About</TD>
	<TD	>|</TD>
	<TD onclick="HideMenu" width="100%" border="2"></TD>
	</TR></TABLE>
<!-- Drop down for QUery -->
<TABLE ID=MyFileMenu class=submenu style="left=10;display:none;">
        <TR><TD	onclick="HideMenu:open"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Open</TD></TR>
        <TR><TD onclick="HideMenu:importfromexcel"
                onmouseover='Submenuover Me'
                onmouseout='Submenuout Me'> Import from Excel</TD></TR>
	<TR><TD	onclick="HideMenu:save"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save</TD></TR>
	<TR><TD	onclick="HideMenu:saveAs"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save As</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:window.close"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Quit</TD></TR>
</TABLE>
<!-- Drop down for Reports -->
<TABLE ID=MyEditMenu class=submenu style="left=50;display:none;">
        <TR><TD	onclick="HideMenu:Email_This_Record"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email This Record</TD></TR>
	<TR><TD	onclick="HideMenu:Email_All_Records"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email All Records</TD></TR>
	<TR><TD	onclick="HideMenu:Email_As_Attachment"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email as Attachment</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:RunScript"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save to</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:ClickTheSpecialReportButton"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> All Disabled Users</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified Today</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersSomeDay"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified...</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportNewUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> New Users Created Today</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:7')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 week</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:30')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 month</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:60')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 2 months</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:MailboxSizeCompare"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Users with mailbox size over...</TD></TR>
</TABLE>
<!-- Drop down for Query Builder -->
<TABLE ID=QueryBuilderMenu class=submenu style="left=97;display:none;">
        <TR><TD	onclick="HideMenu:AddToQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Add recent query to Query Builder</TD></TR>
        <TR><TD	onclick="HideMenu:QueryBuilderRecorder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Query Builder Recorder<input type="checkbox" id="chk_qbrecorder" name="chk_qbrecorder"></TD></TR>
	<TR><TD	onclick="HideMenu:ViewQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> View Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:RunQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Run Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:ClearQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Clear Query Builder</TD></TR>
</TABLE>
<!-- Drop down for Tools -->
<TABLE ID=ToolsMenu class=submenu style="left=170;display:none;">
        <TR><TD	onclick="HideMenu:allowpings"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Allow Pings<input type="checkbox" id="chk_allowpings" name="chk_allowpings"></TD></TR>
        <TR><TD	onclick="HideMenu:LookupLastLogin"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Look up last login<input type="checkbox" id="chk_LookupLastLogin" name="chk_LookupLastLogin"></TD></TR>
        <TR><TD	onclick="HideMenu:tablereports"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Invert emails to table format<input type="checkbox" id="chk_tablereports" name="chk_tablereports"></TD></TR>
	<TR><TD><HR></TD></TR>
        <TR><TD	onclick="HideMenu:RunHTA('HTA1.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 1</TD></TR>
	<TR><TD	onclick="HideMenu:RunHTA('HTA2.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 2</TD></TR>
</TABLE>
<hr>
 <table width="100%" border="0" onclick="HideMenu">
            <tr>
                  <td align="left" colspan="2" valign="top">
                        <table border="0" padding="1">
                              <tr>
                                    <td>
                                         <fieldset>
                                         <LEGEND>Email Settings</LEGEND>
                                         <table border="0">
                                         <tr><td>To:</td><td><button onclick="ShowDialogTo">Resolve</button></td><td><input type="text" id="txt_EmailTo" name="txt_EmailTo" size="50"><input type="hidden" id="txt_EmailToHidden" name="txt_EmailToHidden" size="50"><br></td></td><td rowspan="4" valign="top">Email&nbsp;Body:</td><td rowspan="3" valign="top"><textarea id="txt_EmailBody" name="txt_EmailBody" rows=5 cols=40></TEXTAREA></td></tr>
                                         <tr><td>CC:</td><td><button onclick="ShowDialogCC">Resolve</button></td><td><input type="text" id="txt_EmailCC" name="txt_EmailCC" size="50"><input type="hidden" id="txt_EmailCCHidden" name="txt_EmailCCHidden" size="50"><br></td></tr>
                                         <tr><td>Email Subject:</td><td></td><td><select id="txt_EmailSubject" name="txt_EmailSubject"></select></td></tr>
                                         </table>
                                         </fieldset>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
            <tr>
                  <td align="left" valign="top" width="38%">
                        <table border="0">
                              <tr>
                                    <td>
                                          &nbsp;
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_selectall" name="chk_selectall" checked=True onclick="vbs:SelectAllCheck">Select/Deselect All
                                    </td>
                              </tr>
                              <tr id=tr_seatno>
                                    <td>
                                          Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_seatno" name="chk_seatno" checked=True><input type="text" size="40" id="txt_seatno" name="txt_seatno" onkeypress="vbs:Detect_Search_Field('txt_seatno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacementseatno>
                                    <td>
                                          Replacement Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacementseatno" name="chk_replacementseatno" checked=True><input type="text" size="40" id="txt_replacementseatno" name="txt_replacementseatno">
                                    </td>
                              </tr>
                              <tr id=tr_building>
                                    <td>
                                          Building:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_building" name="chk_building" checked=True><input type="text" size="40" id="txt_building" name="txt_building" onkeypress="vbs:Detect_Search_Field('txt_building')">
                                    </td>
                              </tr>
                              <tr id=tr_extensionno>
                                    <td>
                                          Extension No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_extensionno" name="chk_extensionno" checked=True><input type="text" size="40" id="txt_extensionno" name="txt_extensionno" onkeypress="vbs:Detect_Search_Field('txt_extensionno')">
                                    </td>
                              </tr>
                              <tr id=tr_empid>
                                    <td>
                                          Emp ID:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_empid" name="chk_empid" checked=True><input type="text" size="10" id="txt_empid" name="txt_empid" onkeypress="vbs:Detect_Search_Field('txt_empid')">
                                    </td>
                              </tr>
                              <tr id=tr_department>
                                    <td>
                                          Department:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_department" name="chk_department" checked=True><input type="text" size="50" id="txt_department" name="txt_department" onkeypress="vbs:Detect_Search_Field('txt_department')">
                                    </td>
                              </tr>
                              <tr id=tr_designation>
                                    <td>
                                          Designation:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_designation" name="chk_designation" checked=True><input type="text" size="50" id="txt_designation" name="txt_designation" onkeypress="vbs:Detect_Search_Field('txt_designation')">
                                    </td>
                              </tr>
                              <tr id=tr_name>
                                    <td>
                                          User Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_name" name="chk_name" checked=True><input type="text" size="40" id="txt_name" name="txt_name" onkeypress="vbs:Detect_Search_Field('txt_name')">
<span id="span_userorcontact">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_loginname>
                                    <td>
                                          Login Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_loginname" name="chk_loginname" checked=True><input type="text" size="40" id="txt_loginname" name="txt_loginname" onkeypress="vbs:Detect_Search_Field('txt_loginname')"> 
<span id="span_enabled">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_email>
                                    <td>
                                          Email Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_email" name="chk_email" checked=True><input type="text" size="50" id="txt_email" name="txt_email" onkeypress="vbs:Detect_Search_Field('txt_email')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxsize>
                                    <td>
                                          Mailbox Size (MB):
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxsize" name="chk_mailboxsize" checked=True><input type="text" size="20" id="txt_mailboxsize" name="txt_mailboxsize" onkeypress="vbs:Detect_Search_Field('txt_mailboxsize')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxstore>
                                    <td>
                                          Mailbox Store:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxstore" name="chk_mailboxstore" checked=True><input type="text" size="50" id="txt_mailboxstore" name="txt_mailboxstore" onkeypress="vbs:Detect_Search_Field('txt_mailboxstore')">
                                    </td>
                              </tr>
                              <tr id=tr_mobileno>
                                    <td>
                                          Mobile Number:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mobileno" name="chk_mobileno" checked=True><input type="text" size="20" id="txt_mobileno" name="txt_mobileno" onkeypress="vbs:Detect_Search_Field('txt_mobileno')">
                                    </td>
                              </tr>
                              <tr id=tr_company>
                                    <td>
                                          Company:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_company" name="chk_company" checked=True><input type="text" size="20" id="txt_company" name="txt_company" onkeypress="vbs:Detect_Search_Field('txt_company')">
                                    </td>
                              </tr>
                              <tr id=tr_address>
                                    <td>
                                          Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_address" name="chk_address" checked=True><input type="text" size="20" id="txt_address" name="txt_address" onkeypress="vbs:Detect_Search_Field('txt_address')">
                                    </td>
                              </tr>
                              <tr id=tr_city>
                                    <td>
                                          City:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_city" name="chk_city" checked=True><input type="text" size="20" id="txt_city" name="txt_city" onkeypress="vbs:Detect_Search_Field('txt_city')">
                                    </td>
                              </tr>
                              <tr id=tr_state>
                                    <td>
                                          State:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_state" name="chk_state" checked=True><input type="text" size="20" id="txt_state" name="txt_state" onkeypress="vbs:Detect_Search_Field('txt_state')">
                                    </td>
                              </tr>
                              <tr id=tr_zipcode>
                                    <td>
                                          Zip Code:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_zipcode" name="chk_zipcode" checked=True><input type="text" size="20" id="txt_zipcode" name="txt_zipcode" onkeypress="vbs:Detect_Search_Field('txt_zipcode')">
                                    </td>
                              </tr>
                              <tr id=tr_country>
                                    <td>
                                          Country:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_country" name="chk_country" checked=True><input type="text" size="20" id="txt_country" name="txt_country" onkeypress="vbs:Detect_Search_Field('txt_country')">
                                          &nbsp&nbspMust search by 2 letter country code
                                    </td>
                              </tr>
                              <tr id=tr_homephone>
                                    <td>
                                          Home Phone:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_homephone" name="chk_homephone" checked=True><input type="text" size="20" id="txt_homephone" name="txt_homephone" onkeypress="vbs:Detect_Search_Field('txt_homephone')">
                                    </td>
                              </tr>
                              <tr id=tr_manager>
                                    <td>
                                          Manager:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_manager" name="chk_manager" checked=True><input type="hidden" size="20" id="txt_manager" name="txt_manager"><input type="text" size="20" id="txt_managerseen" name="txt_managerseen" onkeypress="vbs:Detect_Search_Field('txt_managerseen')">
                                    </td>
                              </tr>
                              <tr id=tr_whencreated>
                                    <td>
                                          Date Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_whencreated" name="chk_whencreated" checked=True><input type="text" size="40" id="txt_whencreated" name="txt_whencreated" onkeypress="vbs:Detect_Search_Field('txt_whencreated')"><input type=button value="Pick" onclick="DoCal('txt_whencreated')">
                                    </td>
                              </tr>
                              <tr id=tr_oupathuser>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathuser" name="chk_oupathuser" checked=True><input type="text" size="50" id="txt_oupathuser" name="txt_oupathuser" onkeypress="vbs:Detect_Search_Field('txt_oupathuser')">
                                    </td>
                              </tr>
                              <tr id=tr_lastlogintimestamp>
                                    <td>
                                          Last Login:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_lastlogintimestamp" name="chk_lastlogintimestamp" checked=True><input type="text" size="50" id="txt_lastlogintimestamp" name="txt_lastlogintimestamp" onkeypress="vbs:Detect_Search_Field('txt_lastlogintimestamp')">
                                    </td>
                              </tr>
                              <tr>
                                    <td colspan="2" align="center">
                                          <br>Showing record&nbsp
                                          <span id="span_currentrecord">
                                          0
                                          </span>
                                          &nbsp;of&nbsp;
                                          <span id="span_totalrecords">
                                          0
                                          </span>
                                          <br><br>
                                          <input type="button" value='||< First' name='btnFirstEvent'  onClick='vbs:First_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='<< Previous' name='btnPreviousEvent'  onClick='vbs:Previous_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Next >>' name='btnNextEvent'  onClick='vbs:Next_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Last >||' name='btnLastEvent'  onClick='vbs:Last_Event'><br><br>
                                          <input type="button" value='Email this record' name='btnEmailThisRecord'  onClick='vbs:Email_This_Record'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email all records' name='btnEmailAllRecords'  onClick='vbs:Email_All_Records'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email as attachment' name='btnEmailAsAttachment'  onClick='vbs:Email_As_Attachment'><br><br>
                                          <input type="button" value='Clear Form' name='btnClearForm'  onClick='vbs:Clear_Form("resetGroupLists")'>
                                          <input type="submit" value="Submit" name="btn_submit" onClick="vbs:Submit_Form('Main')">
                                          <input id="runbutton"  class="button" type="button" value="Save to" name="run_button" onClick="Runscript">
                                          <input id="runbutton"  class="button" type="button" value="Change PWD" name="bt1go">
                                          <input id="runbutton"  class="button" type="button" value="Enable/Disable User" name="bt2go">
                                    </td>
                              </tr>
                        </table>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset>
                  <LEGEND>Computer Information</LEGEND>
                  <table>
                              <tr id=tr_notes>
                                    <td valign="top">
                                         Machine Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_notes" name="chk_notes" checked=True><input type="text" size="40" id="txt_notes" name="txt_notes" onkeypress="vbs:Detect_Search_Field('txt_notes')"><input type="button" value='Reset' name='btnResetComputerPassword'  onClick='vbs:ResetComputerPassword'>
<br>IP: <span id="span_computerip"> </span><br>
Status: <span id="span_computeronline"> </span>
                                    </td>
                              </tr>
                              <tr id=tr_computerserialno>
                                    <td>
                                         Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerserialno" name="chk_computerserialno" checked=True><input type="text" size="40" id="txt_computerserialno" name="txt_computerserialno" onkeypress="vbs:Detect_Search_Field('txt_computerserialno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacedmachine>
                                    <td>
                                         Replaced Machine:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedmachine" name="chk_replacedmachine" checked=True><input type="text" size="40" id="txt_replacedmachine" name="txt_replacedmachine">
                                    </td>
                              </tr>
                              <tr id=tr_replacedcomputerserialno>
                                    <td>
                                         Replaced Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedcomputerserialno" name="chk_replacedcomputerserialno" checked=True><input type="text" size="40" id="txt_replacedcomputerserialno" name="txt_replacedcomputerserialno">
                                    </td>
                              </tr>
                              <tr id=tr_oupathcomputer>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathcomputer" name="chk_oupathcomputer" checked=True><input type="text" size="40" id="txt_oupathcomputer" name="txt_oupathcomputer" onkeypress="vbs:Detect_Search_Field('txt_oupathcomputer')">
                                    </td>
                              </tr>
                              <tr id=tr_computeros>
                                    <td>
                                          Computer OS:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computeros" name="chk_computeros" checked=True><input type="text" size="19" id="txt_computeros" name="txt_computeros" onkeypress="vbs:Detect_Search_Field('txt_computeros')">
                                          <input type="text" size="18" id="txt_computerservicepack" name="txt_computerservicepack" onkeypress="vbs:Detect_Search_Field('txt_computerservicepack')">
                                    </td>
                              </tr>
                              <tr id=tr_computerdescription>
                                    <td>
                                         Description:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerdescription" name="chk_computerdescription" checked=True><input type="text" size="40" id="txt_computerdescription" name="txt_computerdescription" onkeypress="vbs:Detect_Search_Field('txt_computerdescription')">
                                    </td>
                              </tr>
                              <tr id=tr_computercreated>
                                    <td>
                                          Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computercreated" name="chk_computercreated" checked=True><input type="text" size="40" id="txt_computercreated" name="txt_computercreated" onkeypress="vbs:Detect_Search_Field('txt_computercreated')"><input type=button value="Pick" onclick="DoCal('txt_computercreated')">
                                    </td>
                              </tr>
                  </table>
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_domaincomputers>
                  <LEGEND><!--<input type="checkbox" id="chk_domaincomputers" name="chk_domaincomputers" checked=True>-->Domain Computers <span id="span_domaincomputers"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_domaincomputers" name="lst_domaincomputers">
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filterdomaincomputers" name="txt_filterdomaincomputers">
                  </fieldset>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset id=tr_groupmembership>
                  <LEGEND><input type="checkbox" id="chk_groupmembership" name="chk_groupmembership" checked=True>Group Membership <span id="span_groupmembership"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_groupnames" name="lst_groupnames" onDblClick="vbs:Submit_Form('Group')">
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filtersecuritygroup" name="txt_filtersecuritygroup">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_dgmembership>
                  <LEGEND><input type="checkbox" id="chk_dgmembership" name="chk_dgmembership" checked=True>Distribution Group Membership <span id="span_dgmembership"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_dgnames" name="lst_dgnames" onDblClick="vbs:Submit_Form('DistributionGroup')">
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filterdgmembership" name="txt_filterdgmembership">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_managerlist>
                  <LEGEND><input type="checkbox" id="chk_managerlist" name="chk_managerlist" checked=True>Manager <span id="span_managerlist"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_managerlist" name="lst_managerlist" onDblClick="vbs:Submit_Form('ManagerList')">
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filtermanagerlist" name="txt_filtermanagerlist">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_subordinates>
                  <LEGEND><input type="checkbox" id="chk_subordinates" name="chk_subordinates" checked=True>Subordinates <span id="span_subordinates"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_subordinates" name="lst_subordinates" onDblClick="vbs:Submit_Form('Subordinate')">
                  
                  </select>
                  </fieldset>
                  <br><br>
                  </td>
            </tr>
      </table>
 </body>

Open in new window

0
 
bsharathAuthor Commented:
I get the attached error. When its opened.When debug goes here
  adoRecordset.Open strQuery, adoConnection, , , 1

ScreenShot089.jpg
0
 
bsharathAuthor Commented:
Previously when i query a group and it has 10 users it could take time and after it retrieves the data when selected next it gets the data fast. But now for each next i click it take some time...

No computers are got into the box... ( I have computers in different OU's in the local AD. Want the script to query just the local Domain computers...

I Get 2 Domain Users groups displayed...

Many of the GSG dont get the users. It shows as there are users in there but when double click it says not found...



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bsharathAuthor Commented:
Previously when i query a group and it has 10 users it could take time and after it retrieves the data when selected next it gets the data fast. But now for each next i click it take some time...

No computers are got into the box... ( I have computers in different OU's in the local AD. Want the script to query just the local Domain computers...

I Get 2 Domain Users groups displayed...

Many of the GSG dont get the users. It shows as there are users in there but when double click it says not found...



0
 
bsharathAuthor Commented:
For all the queries i mention the domain names in the script. Will mentioning he Domian Controller Name be of any use? As we have 10 + DC's...
Just see if that might increase the speed....
0
 
rejoinderCommented:
There are two Domain User groups because each domain has one of these groups (by default).
Selecting the domain controller will not improve the speed in theory - the script tries to contact the nearest DC within the site.  You will notice similar behaviour when opening AD for Users and Computers.  Sometimes one DC is listed at the top left, other times it will connect to another server.
The computer box didn't get filled in because of an error as pointed out with the screen shot.  I think the problem is the number of machines you have is greater than 1000.  I will adjust the code to hopfully get around that.
0
 
bsharathAuthor Commented:
Ok Thx Yes we have 3000+ Systems
0
 
bsharathAuthor Commented:
Ok Thx Yes we have 3000+ Systems
0
 
rejoinderCommented:
I have changed the GUI a little to use a different kind of list box.  I need to display more details so I can help trouble shoot better.  Now if you are getting two Domain Users groups, you can look to see that each group belongs to a different domain by looking at the Distinguished Name column.

I am using different code to pull the computer names so I am hopeful that the app will display all the computer names in your domain.

<head>
<title>User Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="User Information"
     BORDER="thin"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="MAXIMIZE"
     ID="oHTA"
>
<APPLICATION:HTA>
</head>
 
<script language="VBScript">
Const adVarChar = 200
Const VarCharMaxCharacters = 255
Const adFldIsNullable = 32
 
'http://www.experts-exchange.com/Programming/Languages/Q_23807915.html
 
Dim strEmailBCC
Dim strEmailServer
Dim arrSubjectText
Dim arrDomainNames
 
strEmailBCC         = "" 'Enter the BCC field as "Your Name <youremail@yourdomain.com>"
strEmailServer      = "MAILSERVER" 'Exchange server name
arrSubjectText      = array("This is subject text #1","This is subject text #2","This is subject text #3","This is subject text #4","This is subject text #5","This is subject text #6","This is subject text #7","This is subject text #8")
arrToSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
arrCCSpecial        = array("","","","","","","","") 'Fill in the names (to email) so as to match with the subject lines above. Seperate names with a ; eg. "john Doe;Jane Doe"
arrBodySpecial      = array("Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here","Enter text here") 'Fill in the body text which will match the order the subject lines above.
arrCheckBoxSpecial  = array("Default","Default","Default","Default","Default","Default","Default","Default") 'Use the checkbox profile name to have the script match up the subject line to the checkbox profile you have stored.
strEmailFrom        = "" 'Leave Blank if the HTA should determine email address automatically
 
'Uncomment the next line to input your own domain names
'arrDomainNames      = array("DOMAIN","DC=subdomain1,DC=domain,DC=com")
 
boolAllowPing       = False 'Set to true to allow the interface to ping computers.
boolLookupLastLogin = False 'Set to true to allow the interface to query last logons
boolTableReports    = False 'Set to true to allow the interface to use table format reports
 
Dim arrRows
Dim strEmailFrom
Dim strEmailTo
Dim strEmailCC
Dim DataList
Dim globalstrSearchField
Dim globalstrSearchBtnPush
Dim FileName
Dim fModif
Dim LastChildMenu
Dim LastMenu
Dim globalstrQueryBuilder
 
if NOT IsArray(arrDomainNames) then
    GetDomainNames
End If
 
If strEmailFrom = "" Then
    strEmailFrom = mid(GetEmailAddresses(GetUsersEmailAddress),1,len(GetEmailAddresses(GetUsersEmailAddress))-1)
    strEmailFrom = GetUsersEmailAddress & " <" & strEmailFrom & ">"	'Getting email address from logged on user
End if
 
strEmailTo = GetUsersEmailAddress	'Get user name of logged on user so there is a default value when launched
strEmailCC = ""
 
DisplayTitle
Set LastChildMenu = Nothing
Set LastMenu = Nothing
 
Set oShell = CreateObject("WScript.Shell")
fTemp      = oShell.ExpandEnvironmentStrings("%TEMP%")
fAppData   = oShell.ExpandEnvironmentStrings("%APPDATA%")
 
Set MailboxList = CreateObject("ADOR.Recordset")
MailboxList.Fields.Append "legacyExchangeDN", adVarChar, VarCharMaxCharacters
MailboxList.Fields.Append "mailboxsize", adVarChar, VarCharMaxCharacters
MailboxList.Open
 
Set GroupMembershipDB = CreateObject("ADOR.Recordset")
GroupMembershipDB.Fields.Append "SAMAccountName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "PrimaryGroupToken", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "SAMAccountType", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Fields.Append "MemberDistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
GroupMembershipDB.Open
 
Set DomainComputersDB = CreateObject("ADOR.Recordset")
DomainComputersDB.Fields.Append "CN", adVarChar, VarCharMaxCharacters, adFldIsNullable
DomainComputersDB.Fields.Append "DistinguishedName", adVarChar, VarCharMaxCharacters, adFldIsNullable
DomainComputersDB.Open
 
set dicGroupNumbers = CreateObject("Scripting.Dictionary")
set dicManagerList  = CreateObject("Scripting.Dictionary")
 
Sub GetDomainNames
    set objRootDSE   = GetObject("LDAP://RootDSE")
    strBase          = "<LDAP://cn=Partitions," & objRootDSE.Get("ConfigurationNamingContext") & ">;"
    strFilter        = "(&(objectcategory=crossRef)(systemFlags=3));"
    strAttrs         = "name,trustParent,nCName,dnsRoot,distinguishedName;"
    strScope         = "onelevel"
    set objConn      = CreateObject("ADODB.Connection")
    objConn.Provider = "ADsDSOObject"
    objConn.Open "Active Directory Provider"
    set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
    objRS.MoveFirst
    
    set arrDomainNames     = CreateObject("Scripting.Dictionary")
    set dicDomainHierarchy = CreateObject("Scripting.Dictionary")
    set dicDomainRoot      = CreateObject("Scripting.Dictionary")
    
    while not objRS.EOF 
        dicDomainRoot.Add objRS.Fields("name").Value, objRS.Fields("nCName").Value
        if objRS.Fields("trustParent").Value <> "" then
            arrDomainNames.Add objRS.Fields("name").Value, 0
            set objDomainParent = GetObject("LDAP://" & objRS.Fields("trustParent").Value)
            dicDomainHierarchy.Add objRS.Fields("name").Value,objDomainParent.Get("name")
       else 
            arrDomainNames.Add objRS.Fields("name").Value, 1
       end if
       objRS.MoveNext
    wend
    for each strDomain in arrDomainNames
        'msgbox strDomain
    next
End Sub
 
Sub Window_OnLoad
      'Uncomment the following lines to hide them from the GUI
      'tr_seatno.classname="HideFromGUI"
      'tr_replacementseatno.classname="HideFromGUI"
      'tr_building.classname="HideFromGUI"
      'tr_extensionno.classname="HideFromGUI"
      'tr_empid.classname="HideFromGUI"
      'tr_department.classname="HideFromGUI"
      'tr_designation.classname="HideFromGUI"
      'tr_name.classname="HideFromGUI"
      'tr_loginname.classname="HideFromGUI"
      'tr_email.classname="HideFromGUI"
      'tr_mailboxsize.classname="HideFromGUI"
      'tr_mailboxstore.classname="HideFromGUI"
      'tr_mobileno.classname="HideFromGUI"
      'tr_company.classname="HideFromGUI"
      'tr_address.classname="HideFromGUI"
      'tr_city.classname="HideFromGUI"
      'tr_state.classname="HideFromGUI"
      'tr_zipcode.classname="HideFromGUI"
      'tr_country.classname="HideFromGUI"
      'tr_homephone.classname="HideFromGUI"
      'tr_manager.classname="HideFromGUI"
      'tr_whencreated.classname="HideFromGUI"
      'tr_oupathuser.classname="HideFromGUI"
      'tr_lastlogintimestamp.classname="HideFromGui"
      'tr_notes.classname="HideFromGUI"
      'tr_computerserialno.classname="HideFromGUI"
      'tr_replacedmachine.classname="HideFromGUI"
      'tr_replacedcomputerserialno.classname="HideFromGUI"
      'tr_oupathcomputer.classname="HideFromGUI"
      'tr_computeros.classname="HideFromGUI"
      'tr_computerdescription.classname="HideFromGUI"
      'tr_computercreated.classname="HideFromGUI"
      'tr_groupmembership.classname="HideFromGUI"
      'tr_dgmembership.classname="HideFromGUI"
      'tr_managerlist.classname="HideFromGUI"
      'tr_subordinates.classname="HideFromGUI"
      'tr_domaincomputers.classname="HideFromGUI"
      
      TestToSeeWhatLinesAreHidden
      
      Set objlst_groupnames = document.getElementById( "lst_groupnames" )
      If objlst_groupnames Is Nothing Then
          MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
      Else
          With objlst_groupnames
              .View              = 3
              .Width             = 360
              .Height            = 150
              .SortKey           = 0
              .Arrange           = 0
              .LabelEdit         = 1
              .SortOrder         = 0
              .Sorted            = 1
              .MultiSelect       = 0
              .LabelWrap         = -1
              .HideSelection     = -1
              .HideColumnHeaders = 0
              .OLEDragMode       = 0
              .OLEDropMode       = 0
              .Checkboxes        = 0
              .FlatScrollBar     = 0
              .FullRowSelect     = 1
              .GridLines         = 0
              .HotTracking       = 0
              .HoverSelection    = 0
              .PictureAlignment  = 0
              .TextBackground    = 0
              .ForeColor         = -2147483640
              .BackColor         = -2147483643
              .BorderStyle       = 1
              .Appearance        = 1
              .MousePointer      = 0
              .Enabled           = 1
              .ColumnHeaders.Clear
              .ColumnHeaders.Add , , "Group Name", 150
              .ColumnHeaders.Add , , "Users", 50
              .ColumnHeaders.Add , , "Type", 50
              .ColumnHeaders.Add , , "Distinguished Name", 100
              .ColumnHeaders.Add , , "Primary ID", 50
              .ListItems.Clear
          End With
      End If
      
      Set objlst_dgnames = document.getElementById( "lst_dgnames" )
      If objlst_dgnames Is Nothing Then
          MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
      Else
          With objlst_dgnames
              .View              = 3
              .Width             = 360
              .Height            = 150
              .SortKey           = 0
              .Arrange           = 0
              .LabelEdit         = 1
              .SortOrder         = 0
              .Sorted            = 1
              .MultiSelect       = 0
              .LabelWrap         = -1
              .HideSelection     = -1
              .HideColumnHeaders = 0
              .OLEDragMode       = 0
              .OLEDropMode       = 0
              .Checkboxes        = 0
              .FlatScrollBar     = 0
              .FullRowSelect     = 1
              .GridLines         = 0
              .HotTracking       = 0
              .HoverSelection    = 0
              .PictureAlignment  = 0
              .TextBackground    = 0
              .ForeColor         = -2147483640
              .BackColor         = -2147483643
              .BorderStyle       = 1
              .Appearance        = 1
              .MousePointer      = 0
              .Enabled           = 1
              .ColumnHeaders.Clear
              .ColumnHeaders.Add , , "Group Name", 150
              .ColumnHeaders.Add , , "Users", 50
              .ColumnHeaders.Add , , "Type", 50
              .ColumnHeaders.Add , , "Distinguished Name", 100
              .ColumnHeaders.Add , , "Primary ID", 50
              .ListItems.Clear
          End With
      End If
      
      Set objlst_domaincomputers = document.getElementById( "lst_domaincomputers" )
      If objlst_dgnames Is Nothing Then
          MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
      Else
          With objlst_domaincomputers
              .View              = 3
              .Width             = 360
              .Height            = 150
              .SortKey           = 0
              .Arrange           = 0
              .LabelEdit         = 1
              .SortOrder         = 0
              .Sorted            = 1
              .MultiSelect       = 0
              .LabelWrap         = -1
              .HideSelection     = -1
              .HideColumnHeaders = 0
              .OLEDragMode       = 0
              .OLEDropMode       = 0
              .Checkboxes        = 0
              .FlatScrollBar     = 0
              .FullRowSelect     = 1
              .GridLines         = 0
              .HotTracking       = 0
              .HoverSelection    = 0
              .PictureAlignment  = 0
              .TextBackground    = 0
              .ForeColor         = -2147483640
              .BackColor         = -2147483643
              .BorderStyle       = 1
              .Appearance        = 1
              .MousePointer      = 0
              .Enabled           = 1
              .ColumnHeaders.Clear
              .ColumnHeaders.Add , , "Computer", 150
              .ColumnHeaders.Add , , "Distinguished Name", 185
              .ListItems.Clear
          End With
      End If
 
      btnFirstEvent.Disabled = True
      btnPreviousEvent.Disabled = True
      btnNextEvent.Disabled = True
      btnLastEvent.Disabled = True
      btnEmailThisRecord.Disabled = True
      btnEMailAllRecords.Disabled = True
      btnEmailAsAttachment.Disabled = True
      txt_EmailTo.Value = strEmailTo
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      FillGroupList
      FillManagerList
      FillSubjectList
      FillDomainComputers
      GetChkProfiles
      GetMailboxDetails
      chk_TableReports.Checked = boolTableReports
      chk_LookupLastLogin.Checked = boolLookupLastLogin
      chk_AllowPings.Checked = boolAllowPing
      txt_EmailSubject_OnChange
End Sub
 
Sub TestToSeeWhatLinesAreHidden
      'Test to see what lines are hidden and uncheck the boxes
      if tr_seatno.classname="HideFromGUI" then chk_seatno.Checked = False
      if tr_replacementseatno.classname="HideFromGUI" then chk_replacementseatno.Checked = False
      if tr_building.classname="HideFromGUI" then chk_building.Checked = False
      if tr_extensionno.classname="HideFromGUI" then chk_extensionno.Checked = False
      if tr_empid.classname="HideFromGUI" then chk_empid.Checked = False
      if tr_department.classname="HideFromGUI" then chk_department.Checked = False
      if tr_designation.classname="HideFromGUI" then chk_designation.Checked = False
      if tr_name.classname="HideFromGUI" then chk_name.Checked = False
      if tr_loginname.classname="HideFromGUI" then chk_loginname.Checked = False
      if tr_email.classname="HideFromGUI" then chk_email.Checked = False
      if tr_mailboxsize.classname="HideFromGUI" then chk_mailboxsize.Checked = False
      if tr_mailboxstore.classname="HideFromGUI" then chk_mailboxstore.Checked = False
      if tr_mobileno.classname="HideFromGUI" then chk_mobileno.Checked = False
      if tr_company.classname="HideFromGUI" then chk_company.Checked = False
      if tr_address.classname="HideFromGUI" then chk_address.Checked = False
      if tr_city.classname="HideFromGUI" then chk_city.Checked = False
      if tr_state.classname="HideFromGUI" then chk_state.Checked = False
      if tr_zipcode.classname="HideFromGUI" then chk_zipcode.Checked = False
      if tr_country.classname="HideFromGUI" then chk_country.Checked = False
      if tr_homephone.classname="HideFromGUI" then chk_homephone.Checked = False
      if tr_manager.classname="HideFromGUI" then chk_manager.Checked = False
      if tr_whencreated.classname="HideFromGUI" then chk_whencreated.Checked = False
      if tr_oupathuser.classname="HideFromGUI" then chk_oupathuser.Checked = False
      if tr_lastlogintimestamp.classname="HideFromGUI" then chk_lastlogintimestamp.Checked = False
      if tr_notes.classname="HideFromGUI" then chk_notes.Checked = False
      if tr_computerserialno.classname="HideFromGUI" then chk_computerserialno.Checked = False
      if tr_replacedmachine.classname="HideFromGUI" then chk_replacedmachine.Checked = False
      if tr_replacedcomputerserialno.classname="HideFromGUI" then chk_replacedcomputerserialno.Checked = False
      if tr_oupathcomputer.classname="HideFromGUI" then chk_oupathcomputer.Checked = False
      if tr_computeros.classname="HideFromGUI" then chk_computeros.Checked = False
      if tr_computerdescription.classname="HideFromGUI" then chk_computerdescription.Checked = False
      if tr_computercreated.classname="HideFromGUI" then chk_computercreated.Checked = False
      if tr_groupmembership.classname="HideFromGUI" then chk_groupmembership.Checked = False
      if tr_dgmembership.classname="HideFromGUI" then chk_dgmembership.Checked = False
      if tr_managerlist.classname="HideFromGUI" then chk_managerlist.Checked = False
      if tr_subordinates.classname="HideFromGUI" then chk_subordinates.Checked = False
End sub
 
Sub Clear_Form(resetGroupLists)
      txt_seatno.Value = ""
      txt_seatno.style.backgroundColor="#FFFFFF"
      txt_seatno.Disabled = False
      txt_replacementseatno.Value = ""
      txt_replacementseatno.style.backgroundColor="#FFFFFF"
      txt_replacementseatno.Disabled = False
      txt_building.Value = ""
      txt_building.style.backgroundColor="#FFFFFF"
      txt_building.Disabled = False
      txt_extensionno.Value = ""
      txt_extensionno.style.backgroundColor="#FFFFFF"
      txt_extensionno.Disabled = False
      txt_empid.Value = ""
      txt_empid.style.backgroundColor="#FFFFFF"
      txt_empid.Disabled = False
      txt_department.Value = ""
      txt_department.style.backgroundColor="#FFFFFF"
      txt_department.Disabled = False
      txt_designation.Value = ""
      txt_designation.style.backgroundColor="#FFFFFF"
      txt_designation.Disabled = False
      txt_name.Value = ""
      txt_name.style.backgroundColor="#FFFFFF"
      txt_name.Disabled = False
      txt_loginname.Value = ""
      txt_loginname.style.backgroundColor="#FFFFFF"
      txt_loginname.Disabled = False
      txt_email.Value = ""
      txt_email.style.backgroundColor="#FFFFFF"
      txt_email.Disabled = False
      txt_mailboxsize.Value = ""
      txt_mailboxsize.style.backgroundColor="#FFFFFF"
      txt_mailboxsize.Disabled = False
      txt_mailboxstore.Value = ""
      txt_mailboxstore.style.backgroundColor="#FFFFFF"
      txt_mailboxstore.Disabled = False
      txt_notes.Value = ""
      txt_notes.style.backgroundColor="#FFFFFF"
      txt_notes.Disabled = False
      txt_computerserialno.Value = ""
      txt_computerserialno.style.backgroundColor="#FFFFFF"
      txt_computerserialno.Disabled = False
      txt_replacedmachine.Value = ""
      txt_replacedmachine.Disabled = False
      txt_replacedmachine.style.backgroundcolor="#FFFFFF"
      txt_replacedcomputerserialno.value = ""
      txt_replacedcomputerserialno.Disabled = False
      txt_replacedcomputerserialno.Style.backgroundcolor="#FFFFFF"
      txt_oupathcomputer.Value = ""
      txt_oupathcomputer.style.backgroundColor="#FFFFFF"
      txt_oupathcomputer.Disabled = False
      txt_computeros.Value = ""
      txt_computeros.Style.backgroundColor="#FFFFFF"
      txt_computeros.Disabled = False
      txt_computerservicepack.Value = ""
      txt_computerservicepack.Style.backgroundColor="#FFFFFF"
      txt_computerservicepack.Disabled = False
      txt_computercreated.Value = ""
      txt_computercreated.Style.backgroundColor="#FFFFFF"
      txt_computercreated.Disabled = False
      txt_computerdescription.Value = ""
      txt_computerdescription.Style.backgroundColor="#FFFFFF"
      txt_computerdescription.Disabled = False
      txt_mobileno.Value = ""
      txt_mobileno.style.backgroundColor="#FFFFFF"
      txt_mobileno.Disabled = False
      txt_company.Value = ""
      txt_company.style.backgroundColor="#FFFFFF"
      txt_company.Disabled = False
      txt_address.Value = ""
      txt_address.style.backgroundColor="#FFFFFF"
      txt_address.Disabled = False
      txt_city.Value = ""
      txt_city.style.backgroundColor="#FFFFFF"
      txt_city.Disabled = False
      txt_state.Value = ""
      txt_state.style.backgroundColor="#FFFFFF"
      txt_state.Disabled = False
      txt_zipcode.Value = ""
      txt_zipcode.style.backgroundColor="#FFFFFF"
      txt_zipcode.Disabled = False
      txt_country.Value = ""
      txt_country.style.backgroundColor="#FFFFFF"
      txt_country.Disabled = False
      txt_homephone.Value = ""
      txt_homephone.style.backgroundColor="#FFFFFF"
      txt_homephone.Disabled = False
      txt_manager.Value = ""
      txt_manager.style.backgroundColor="#FFFFFF"
      txt_manager.Disabled = False
      txt_managerseen.Value = ""
      txt_managerseen.style.backgroundColor="#FFFFFF"
      txt_managerseen.Disabled = False
      txt_whencreated.Value = ""
      txt_whencreated.style.backgroundColor="#FFFFFF"
      txt_whencreated.Disabled = False
      txt_oupathuser.Value = ""
      txt_oupathuser.style.backgroundColor="#FFFFFF"
      txt_oupathuser.Disabled = False
      txt_lastlogintimestamp.Value = ""
      txt_lastlogintimestamp.style.backgroundcolor="#FFFFFF"
      txt_lastlogintimestamp.Disabled = False
      txt_FilterSecurityGroup.Value = ""
      txt_FilterSecurityGroup.style.backgroundcolor="#FFFFFF"
      txt_FilterSecurityGroup.Disabled = False
      txt_filterdgmembership.Value = ""
      txt_filterdgmembership.style.backgroundcolor="#FFFFFF"
      txt_filterdgmembership.Disabled = False
      txt_filtermanagerlist.Value = ""
      txt_filtermanagerlist.style.backgroundcolor="#FFFFFF"
      txt_filtermanagerlist.Disabled = False
      txt_filterdomaincomputers.Value = ""
      txt_filterdomaincomputers.style.backgroundcolor="#FFFFFF"
      txt_filterdomaincomputers.Disabled = False
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
      btnEmailThisRecord.Style.Visibility = "Hidden"
      btnEMailAllRecords.Style.Visibility = "Hidden"
      btnEmailAsAttachment.Style.Visibility = "Hidden"
      span_currentrecord.InnerHTML = "0"
      span_totalrecords.InnerHTML = "0"
      span_computerip.InnerHTML = ""
      span_computerOnline.InnerHTML = ""
      span_enabled.InnerHTML = ""
      span_userorcontact.InnerHTML = ""
      if lcase(resetGroupLists) = lcase("resetGroupLists") then
          GroupMembershipDB.Filter = ""
          GroupMembershipDB.MoveFirst
          Do While Not GroupMembershipDB.EOF
              GroupMembershipDB.Delete
              GroupMembershipDB.MoveNext
          Loop
          FillGroupList
          populatedomaincomputers
      end if
      For Each objOption in lst_subordinates.Options
          objOption.RemoveNode
      Next
      PopulateManagerList
End Sub
 
Sub Submit_Form(btnPush)
 
      arrFields = Array(_
            "txt_seatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_notes", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_oupathuser", _
            "txt_computerserialno", _
            "txt_whencreated", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computercreated", _
            "txt_filtersecuritygroup", _
            "txt_filterdgmembership", _
            "txt_filtermanagerlist", _
            "txt_filterdomaincomputers" _
      )
      
      boolValid = False
      For Each strField In arrFields
            If Eval(strField & ".Disabled") = True Then
                  boolValid = True
            End If
            If Eval(strField & ".Disabled") = False Then
                  strCurrentField = strField
            End If
      Next
      
      If boolValid = False Then strCurrentField = "INVALID"
      
      Select Case strCurrentField
            Case "txt_seatno"
                  If txt_seatno.Value = "" Then
                  	strSearchField = "(info=*)"
                  Else
                  	strSearchField = "(info=*" & txt_seatno.Value & "*)"
                  End If
            Case "txt_building"
                  If txt_building.Value = "" Then
                  	strSearchField = "(physicalDeliveryOfficeName=*)"
                  Else
                  	strSearchField = "(physicalDeliveryOfficeName=*" & txt_building.Value & "*)"
                  End If
            Case "txt_extensionno"
                  If txt_extensionno.Value = "" Then
                        strSearchField = "(telephoneNumber=*)"
                  Else
                        strSearchField = "(telephoneNumber=*" & txt_extensionno.Value & "*)"
                  End If
            Case "txt_empid"
                  If txt_empid.Value = "" Then
                        strSearchField = "(description=*)"
                  Else
                        strSearchField = "(description=*" & txt_empid.Value & "*)"
                  End If
            Case "txt_department"
                  If txt_department.Value = "" Then
                        strSearchField = "(department=*)"
                  Else
                        strSearchField = "(department=*" & txt_department.Value & "*)"
                  End If
            Case "txt_designation"
                  If txt_designation.Value = "" Then
                        strSearchField = "(title=*)"
                  Else
                        strSearchField = "(title=*" & txt_designation.Value & "*)"
                  End If
            Case "txt_name"
                  If txt_name.Value = "" Then
                        strSearchField = "(cn=*)"
                  Else
                        strSearchField = "(cn=*" & txt_name.Value & "*)"
                  End If
            Case "txt_loginname"
                  If txt_loginname.Value = "" Then
                        strSearchField = "(samAccountName=*)"
                  Else
                        strSearchField = "(samAccountName=*" & txt_loginname.Value & "*)"
                  End If
            Case "txt_email"
                  If txt_email.Value = "" Then
                        strSearchField = "(mail=*)"
                  Else
                        strSearchField = "(mail=*" & txt_email.Value & "*)"
                  End If
            Case "txt_notes"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_notes.Value & "*)"
                  End If
            Case "txt_mobileno"
                  If txt_mobileno.Value = "" Then
                        strSearchField = "(mobile=*)"
                  Else
                        strSearchField = "(mobile=*" & txt_mobileno.Value & "*)"
                  End If
            Case "txt_company"
                  If txt_company.Value = "" Then
                        strSearchField = "(company=*)"
                  Else
                        strSearchField = "(company=*" & txt_company.Value & "*)"
                  End If
            Case "txt_address"
                  If txt_address.Value = "" Then
                        strSearchField = "(streetAddress=*)"
                  Else
                        strSearchField = "(streetAddress=*" & txt_address.Value & "*)"
                  End If
            Case "txt_city"
                  If txt_city.Value = "" Then
                        strSearchField = "(l=*)"
                  Else
                        strSearchField = "(l=*" & txt_city.Value & "*)"
                  End If
            Case "txt_state"
                  If txt_state.Value = "" Then
                        strSearchField = "(st=*)"
                  Else
                        strSearchField = "(st=*" & txt_state.Value & "*)"
                  End If
            Case "txt_zipcode"
                  If txt_zipcode.Value = "" Then
                        strSearchField = "(postalCode=*)"
                  Else
                        strSearchField = "(postalCode=*" & txt_zipcode.Value & "*)"
                  End If
            Case "txt_country"
                  If txt_country.Value = "" Then
                        strSearchField = "(c=*)"
                  Else
                        strSearchField = "(c=*" & txt_country.Value & "*)"
                  End If
            Case "txt_homephone"
                  If txt_homephone.Value = "" Then
                        strSearchField = "(homePhone=*)"
                  Else
                        strSearchField = "(homePhone=*" & txt_homephone.Value & "*)"
                  End If
            Case "txt_managerseen"
                  If txt_managerseen.Value = "" Then
                        strSearchField = "(manager=*)"
                  Else
                        strSearchField = GetManagerDN(txt_managerseen.Value)
                  End If
            Case "txt_oupathuser"
                  If txt_oupathuser.Value <> "" Then
                        strSearchField = GetOUMembers(txt_oupathuser.Value)
                  End If
            Case "txt_whencreated"
                  If txt_whencreated.Value = "" Then
                        strSearchField = "(whenCreated=*)"
                  Else
                        if NOT IsDate(txt_whencreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strWhenCreated = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
                            strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
                        end if
                  End If
            Case "txt_computerserialno"
                  If txt_notes.Value = "" Then
                        strSearchField = "(info=*)"
                  Else
                        strSearchField = "(info=*" & txt_computerserialno.Value & "*)"
                  End If
            Case "txt_oupathcomputer"
                  If txt_oupathcomputer.Value = "" then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersBasedOnOU(txt_oupathcomputer.Value)
                  end if
            Case "txt_computeros"
                  If txt_computeros.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        strSearchField = GetComputersForOSQuery(txt_computeros.Value)
                  End If
            Case "txt_computercreated"
                  If txt_computercreated.Value = "" Then
                        strSearchField = "INVALID"
                  else
                        if NOT IsDate(txt_computercreated.Value) then
                            msgbox "Invalid date - enter as dd/mm/yyyy"
                            strSearchField = "INVALID"
                        else
                            strSearchField = GetComputersForDateCreatedQuery(txt_computercreated.Value)
                        End If
                  End If
            Case "txt_filtersecuritygroup"
                  if lst_groupnames.ListItems.Count = 1 then
                        lst_groupnames.ListItems(1).Selected = True
                        btnPush = "Group"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filterdgmembership"
                  if lst_dgnames.ListItems.Count = 1 then
                        lst_dgnames.ListItems(1).Selected = True
                        btnPush = "DistributionGroup"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filtermanagerlist"
                  if lst_managerlist.Options.Length = 1 then
                        lst_managerlist.Options(0).Selected = True
                        btnPush = "ManagerList"
                  else
                        strSearchField = "INVALID"
                  end if
            Case "txt_filterdomaincomputers"
                  if lst_domaincomputers.ListItems.Count = 1 then
                        lst_domaincomputers.ListItems(1).Selected = True
                        strSearchField = "(info=*" & lst_domaincomputers.SelectedItem.Text & "*)"
                  else
                        strSearchField = "INVALID"
                  end if
            Case Else
                  strSearchField = "INVALID"
      End Select
      
      if btnPush = "Disabled" then
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)"
      end if
      
      if btnPush = "Group" then
          sMemberOf       = lst_groupnames.SelectedItem.ListSubItems(3).Text
          sprimaryGroupID = lst_groupnames.SelectedItem.ListSubItems(4).Text
          strSearchField  = "(|(memberOf=" & sMemberOf & ")(primaryGroupID=" & sprimaryGroupID & "))"
      end if
      
      if btnPush = "DistributionGroup" then
          sMemberOf       = lst_dgnames.SelectedItem.ListSubItems(3).Text
          sprimaryGroupID = lst_dgnames.SelectedItem.ListSubItems(4).Text
          strSearchField  = "(|(memberOf=" & sMemberOf & ")(primaryGroupID=" & sprimaryGroupID & "))"
      end if
      
      if btnPush = "ManagerList" then
          For i = 0 to (lst_ManagerList.Options.Length - 1)
              If (lst_ManagerList.Options(i).Selected) Then
                  strSearchField = "(distinguishedname=" & lst_ManagerList.Options(i).Value & ")" 
              End If
          Next
      end if
      
      if btnPush = "Subordinate" then
          For i = 0 to (lst_subordinates.Options.Length - 1)
              If (lst_subordinates.Options(i).Selected) Then
                  arrSubordinateNames = split(lst_subordinates.Options(i).Value,";")
                  strSearchField = "(samAccountName=*" & arrSubordinateNames(0) & "*)"
              End If
          Next
      end if
      
      if btnPush = "DisabledToday" then
          strWhenChanged = Year(txt_whencreated.Value) & Right("0" & Month(txt_whencreated.Value), 2) & Right("0" & Day(txt_whencreated.Value), 2)
          strSearchField = "(userAccountControl:1.2.840.113556.1.4.803:=2)(whenChanged>=" & strWhenChanged & "000000.0Z)(whenChanged<=" & strWhenChanged & "235959.0Z)"
      end if
      
      if btnPush = "FileOpen" then
          strSearchField = globalStrSearchField
          btnPush = globalStrSearchBtnPush
      End if
      
      boolLogonSearch = False
      dmtDateToCompare = Date()
      
      if InStr(btnPush,"Logon:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolLogonSearch = True
          intNumberOfDays = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
          dmtDateToCompare = Date() - intNumberOfDays
          
          if NOT chk_LookupLastLogin.Checked then
              chk_LookupLastLogin.Checked = True
              boolLookupLastLogin = True
          end if
          
      end if
      
      boolMailboxSizeSearch = False
      
      if InStr(btnPush,"MailboxSize:") > 0 then
          strSearchField = "(samAccountName=*)"
          boolMailboxSizeSearch = True
          intMailboxSizeToCompare = right(btnPush,Len(btnPush)-InStr(btnPush,":"))
      end if
      
      Clear_Form ""
      
      If strSearchField <> "INVALID" Then
            Set adoCommand = CreateObject("ADODB.Command")
            Set adoConnection = CreateObject("ADODB.Connection")
            adoConnection.Provider = "ADsDSOObject"
            adoConnection.Open "Active Directory Provider"
            adoCommand.ActiveConnection = adoConnection
            
            boolFoundRecords = False
            
            for each strDomain in arrDomainNames
                  ' Search entire Active Directory domain.
                  strBase = "<LDAP://" & strDomain & ">"
                  
                  strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
 
                  ' Comma delimited list of attribute values to retrieve.
                  if boolLookupLastLogin then
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID,lastLogon"
                  else
                        strAttributes = "physicalDeliveryOfficeName,TelephoneNumber,description,Department,Title,cn,samAccountName,mail,Info,Mobile,company,streetAddress,l,st,postalCode,c,homePhone,manager,whenCreated,distinguishedName,userAccountControl,legacyExchangeDN,homeMDB,primaryGroupID"
                  end if
                  ' Construct the LDAP syntax query.
                  strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                  adoCommand.CommandText = strQuery
                  adoCommand.Properties("Page Size") = 100
                  adoCommand.Properties("Timeout") = 30
                  adoCommand.Properties("Cache Results") = False
                  adoCommand.Properties("Sort On") = "cn"
                  ' Run the query.
                  Set adoRecordset = adoCommand.Execute
                  ' Enumerate the resulting recordset.
                  strDetails = ""
                  If Not adoRecordset.EOF Then
                        boolFoundRecords = True
                        Do Until adoRecordset.EOF
                              mailboxlist.filter = "legacyExchangeDN = '" & adoRecordset.Fields("legacyExchangeDN").Value & "'"
                              if NOT mailboxlist.EOF then
                                    intMailboxSize = mailboxlist.fields.Item("mailboxsize")
                              else
                                    intMailboxSize = "0"
                              End if
                              if boolLookupLastLogin then
                                    if NOT IsNull(adoRecordset.Fields("lastLogon").Value) then
                                          Set objLastLogon = adoRecordset.Fields("lastLogon").Value
                                          intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart 
                                          intLastLogonTime = intLastLogonTime / (60 * 10000000)
                                          intLastLogonTime = intLastLogonTime / 1440
                                          intLastLogonTime = intLastLogonTime + #1/1/1601#
                                          if intLastLogonTime = #1/1/1601# then
                                                intLastLogonTime = ""
                                          end if
                                    else
                                          intLastLogonTime = ""
                                    end if
                              else
                                    intLastLogonTime = ""
                              end if
                              if NOT IsDate(intLastLogonTime) then
                                    dmtDateToCompareTo = dmtDateToCompare
                              else
                                    dmtDateToCompareTo = intLastLogonTime
                              end if
                              if (CDate(dmtDateToCompareTo) >= CDate(dmtDateToCompare)) AND boolLogonSearch then
                                    'Do nothing
                              else
                                    if (CInt(intMailboxSize) < CInt(intMailboxSizeToCompare)) AND boolMailboxSizeSearch then
                                          'Do nothing
                                    else
                                          If strDetails <> "" Then strDetails = strDetails & "|TR|"
                                          if adoRecordset.Fields("userAccountControl").Value AND 2 then
                                                strEnabled = "Disabled"
                                          else
                                                strEnabled = "Enabled"
                                          End If
                                          strMachineName = ""
                                          strBuilding = ""
                                          strSerialNumber = ""
                                          If IsNull(adoRecordset.Fields("Info").Value) = False Then
                                                arrNotesField = Split(adoRecordset.Fields("Info").Value,vbCRLF)
                                                for each strLine in arrNotesField
                                                      if InStr(UCase(strLine),"MACHINE NAME : ") then
                                                            strMachineName = trim(mid(strLine,15))
                                                      End if
                                                      if InStr(UCase(strLine),"LOCATION : ") then
                                                            strBuilding = trim(mid(strLine,11))
                                                      End if
                                                      if InStr(UCase(strLine),"SERIAL NO : ") then
                                                            strSerialNumber = trim(mid(strLine,12))
                                                      End if
                                                next
                                                strDetails = strDetails & replace(strBuilding,vbCRLF,"")
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("physicalDeliveryOfficeName").Value &_
                                          "|TD|" & adoRecordset.Fields("TelephoneNumber").Value
                                          If IsNull(adoRecordset.Fields("Description").Value) = False Then
                                                strDetails = strDetails & "|TD|" & Join(adoRecordset.Fields("description").Value)
                                          Else
                                                strDetails = strDetails & "|TD|"
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("Department").Value &_
                                          "|TD|" & adoRecordset.Fields("Title").Value &_
                                          "|TD|" & Replace(adoRecordset.Fields("cn").Value, "CN=", "") &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("mail").Value &_
                                          "|TD|" & strMachineName &_
                                          "|TD|" & adoRecordset.Fields("Mobile").Value &_
                                          "|TD|" & adoRecordset.Fields("company").Value &_
                                          "|TD|" & adoRecordset.Fields("streetAddress").Value &_
                                          "|TD|" & adoRecordset.Fields("l").Value &_
                                          "|TD|" & adoRecordset.Fields("st").Value &_
                                          "|TD|" & adoRecordset.Fields("postalCode").Value &_
                                          "|TD|" & adoRecordset.Fields("c").Value &_
                                          "|TD|" & adoRecordset.Fields("homePhone").Value &_
                                          "|TD|" & adoRecordset.Fields("manager").Value &_
                                          "|TD|" & adoRecordset.Fields("whenCreated").Value &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("distinguishedName").Value &_
                                          "|TD|" & intLastLogonTime &_
                                          "|TD|" & strSerialNumber &_
                                          "|TD|" & UCASE(strEnabled) &_
                                          "|TD|" & intMailboxSize &_
                                          "|TD|" & GetMailboxStore(adoRecordset.Fields("homeMDB").Value) &_
                                          "|TD|" & adoRecordset.Fields("primaryGroupID").Value
                                          strDetails = replace(strDetails,vbCRLF,"")
                                    end if
                              end if
                              adoRecordset.MoveNext
                        Loop
                  End If
            next
            
            if NOT boolFoundRecords then
                  MsgBox "No records were found"
                  span_currentrecord.InnerHTML = 0
                  span_totalrecords.InnerHTML  = 0
            else
                  arrRows = ""
                  arrRows = Split(strDetails, "|TR|")
                  If UBound(arrRows) < 0 Then
                        span_currentrecord.InnerHTML = 0
                        span_totalrecords.InnerHTML = 0
                  Else
                        span_currentrecord.InnerHTML = 1
                        Get_Event
                        span_totalrecords.InnerHTML = UBound(arrRows)+1
                  End If
            End if
            
            ' Clean up.
            adoRecordset.Close
            Set adoRecordset = Nothing
            
            adoConnection.Close
      
            If strDetails = "" Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = True
                  btnEMailAllRecords.Disabled = True
                  btnEmailAsAttachment.Disabled = True
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Hidden"
                  btnEMailAllRecords.Style.Visibility = "Hidden"
                  btnEmailAsAttachment.Style.Visibility = "Hidden"
            ElseIf UBound(arrRows) = 0 Then
                  btnFirstEvent.Disabled = True
                  btnPreviousEvent.Disabled = True
                  btnNextEvent.Disabled = True
                  btnLastEvent.Disabled = True
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Hidden"
                  btnPreviousEvent.Style.Visibility = "Hidden"
                  btnNextEvent.Style.Visibility = "Hidden"
                  btnLastEvent.Style.Visibility = "Hidden"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            Else
                  btnFirstEvent.Disabled = False
                  btnPreviousEvent.Disabled = False
                  btnNextEvent.Disabled = False
                  btnLastEvent.Disabled = False
                  btnEmailThisRecord.Disabled = False
                  btnEMailAllRecords.Disabled = False
                  btnEmailAsAttachment.Disabled = False
                  btnFirstEvent.Style.Visibility = "Visible"
                  btnPreviousEvent.Style.Visibility = "Visible"
                  btnNextEvent.Style.Visibility = "Visible"
                  btnLastEvent.Style.Visibility = "Visible"
                  btnEmailThisRecord.Style.Visibility = "Visible"
                  btnEMailAllRecords.Style.Visibility = "Visible"
                  btnEmailAsAttachment.Style.Visibility = "Visible"
            End If
            globalStrSearchBtnPush = BtnPush
            globalstrSearchField = strSearchField
            if chk_qbrecorder.Checked then
                  AddToQueryBuilder
            end if
      Else
            MsgBox "Please type a search request into one of the fields, then click Submit."
      End If
 
      if InStr(Join(arrFields),strCurrentField) then
            if strSearchField <> "INVALID" then
                  execute(strCurrentField & ".focus")
                  execute(strCurrentField & ".select()")
            end if
      end if
End Sub
 
Sub Get_Event
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	txt_seatno.Value = arrData(0)
	txt_building.Value = arrData(1)
	txt_extensionno.Value = arrData(2)
	txt_empid.Value = arrData(3)
	txt_department.Value = arrData(4)
	txt_designation.Value = arrData(5)
	txt_name.Value = arrData(6)
	txt_loginname.Value = arrData(7)
	txt_email.Value = arrData(8)
        txt_mailboxsize.Value = arrData(25)
        txt_mailboxstore.Value = arrData(26)
	txt_notes.Value = arrData(9)
        if boolAllowPing then PingComputer arrData(9)
        txt_computerserialno.Value = arrData(23)
        arrTemp = GetComputerInfo(arrData(9))
	if IsArray(arrTemp) then
	        txt_oupathcomputer.value = GetOUPath(replace(arrTemp(0),"""",""))
	        txt_computeros.value = replace(arrTemp(1),"""","")
	        txt_computerservicepack.value = replace(arrTemp(2),"""","")
	        txt_computerdescription.value = replace(arrTemp(4),"""","")
	        txt_computercreated.value = replace(arrTemp(3),"""","")
	else
	        txt_oupathcomputer.value = ""
	        txt_computeros.value = ""
	        txt_computerservicepack.value = ""
	        txt_computerdescription.value = ""
	        txt_computercreated.value = ""
	End if
	txt_mobileno.Value = arrData(10)
	txt_company.Value = arrData(11)
	txt_address.Value = arrData(12)
	txt_city.Value = arrData(13)
	txt_state.Value = arrData(14)
	txt_zipcode.Value = arrData(15)
	txt_country.Value = arrData(16)
	txt_homephone.Value = arrData(17)
	txt_manager.Value = arrData(18)
        For Each objOption in lst_managerlist.Options
            objOption.RemoveNode
        Next
        span_managerlist.InnerHTML = "(0)"
        if txt_manager.Value <> "" then
            txt_managerseen.Value = mid(txt_manager.Value,4,instr(txt_manager.Value,",")-4)
            set newOption = document.createElement("OPTION")
            newOption.Text = txt_managerseen.Value & " (" & GetSubordinateNumbers(txt_manager.Value) & ")"
            newOption.Value = txt_manager.Value
            lst_managerlist.Add newOption
            span_managerlist.InnerHTML = "(1)"
        else
            txt_managerseen.Value = txt_manager.Value
        end if
	txt_whencreated.Value = arrData(19)
        txt_oupathuser.value = GetOUPath(arrData(21))
        txt_lastlogintimestamp.value = arrData(22)
        span_enabled.InnerHTML = arrData(24)
        if txt_loginname.Value <> "" then
            span_userorcontact.InnerHTML = "USER"
        else
            span_userorcontact.InnerHTML = "CONTACT"
        end if
        FillGroupMembershipList arrData(21), arrData(27)
End Sub
 
Sub First_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML < 1 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = 1 Then
                  MsgBox "You are already viewing the first record."
            Else
                  span_currentrecord.InnerHTML = 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Previous_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_currentrecord.InnerHTML > 1 Then
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML - 1
                  Get_Event
            ElseIf span_currentrecord.InnerHTML = 1 Then
                        MsgBox "You are already viewing the first record."
            Else
                  MsgBox "There are no records to display"
            End If
      End If
 
End Sub
 
Sub Next_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records for to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                  MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML + 1
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Last_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                        MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_totalrecords.InnerHTML
                  Get_Event
            End If
      End If
      
End Sub
 
Sub Detect_Search_Field(strCurrentField)
      arrFields = Array(_
            "txt_seatno", _
            "txt_replacementseatno", _
            "txt_building", _
            "txt_extensionno", _
            "txt_empid", _
            "txt_department", _
            "txt_designation", _
            "txt_name", _
            "txt_loginname", _
            "txt_email", _
            "txt_mailboxsize", _
            "txt_mailboxstore", _
            "txt_notes", _
            "txt_computerserialno", _
            "txt_replacedmachine", _
            "txt_replacedcomputerserialno", _
            "txt_oupathcomputer", _
            "txt_computeros", _
            "txt_computerservicepack", _
            "txt_computerdescription", _
            "txt_computercreated", _
            "txt_mobileno", _
            "txt_company", _
            "txt_address", _
            "txt_city", _
            "txt_state", _
            "txt_zipcode", _
            "txt_country", _
            "txt_homephone", _
            "txt_managerseen", _
            "txt_whencreated", _
            "txt_oupathuser", _
            "txt_lastlogintimestamp", _
            "txt_filtersecuritygroup", _
            "txt_filterdgmembership", _
            "txt_filtermanagerlist", _
            "txt_filterdomaincomputers" _
      )
      
      For Each strField In arrFields
            If LCase(strField) <> LCase(strCurrentField) Then
                  Execute strField & ".style.backgroundColor=""#D3D3D3"""
                  Execute strField & ".Disabled = True"
            End If
      Next
End Sub
 
Function CreateHeaderRow(CSVorTABLE)
    Dim arrHeader()
    x = 0
    if chk_seatno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Seat No"""
        x = x + 1
    end if
    
    if chk_building.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Building"""
        x = x + 1
    end if
    
    if chk_extensionno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Extension"""
        x = x + 1
    end if
    
    if chk_empid.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Emp ID"""
        x = x + 1
    end if
    
    if chk_department.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Department"""
        x = x + 1
    end if
    
    if chk_designation.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Designation"""
        x = x + 1
    end if
         
    if chk_name.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """User Name"""
        x = x + 1
    end if
    
    if chk_loginname.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Login Name"""
        x = x + 1
    end if
    
    if chk_email.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Email Address"""
        x = x + 1
    end if
    
    if chk_mailboxsize.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Size (MB)"""
        x = x + 1
    end if
    
    if chk_mailboxstore.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mailbox Store"""
        x = x + 1
    end if
    
    if chk_notes.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer"""
        x = x + 1
    end if
    
    if chk_computerserialno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Serial No"""
        x = x + 1
    end if
    
    if chk_oupathcomputer.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - Computer"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer OS"""
        x = x + 1
    end if
    
    if chk_computeros.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Service Pack"""
        x = x + 1
    end if
    
    if chk_computerdescription.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Description"""
        x = x + 1
    end if
    
    if chk_computercreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Computer Account Created"""
        x = x + 1
    end if
    
    if chk_mobileno.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Mobile"""
        x = x + 1
    end if
    
    if chk_company.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Company"""
        x = x + 1
    end if
    
    if chk_address.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Address"""
        x = x + 1
    end if
    
    if chk_city.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """City"""
        x = x + 1
    end if
    
    if chk_state.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """State"""
        x = x + 1
    end if
    
    if chk_zipcode.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Zip Code"""
        x = x + 1
    end if
    
    if chk_country.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Country"""
        x = x + 1
    end if
    
    if chk_homephone.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Home Phone"""
        x = x + 1
    end if
    
    if chk_manager.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Manager"""
        x = x + 1
    end if
    
    if chk_subordinates.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Subordinates"""
        x = x + 1
    end if
    
    if chk_whencreated.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Date Created"""
        x = x + 1
    end if
    
    if chk_oupathuser.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """OU Path - User"""
        x = x + 1
    end if
    
    if chk_lastlogintimestamp.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Last Logon"""
        x = x + 1
    end if
    
    if chk_groupmembership.Checked then
        ReDim Preserve arrHeader(x)
        arrHeader(x) = """Group Membership"""
        x = x + 1
    end if
 
    if CSVorTABLE <> "" then
        strHeader = strHeader & "<tr>"
        for n = 0 to UBound(arrHeader)-1
            strHeader = strHeader & "<td valign=""top"" align=""left""><b>" & replace(arrHeader(n),"""","") & "</b></td>"
        next
        strHeader = strHeader & "</tr>" & vbCRLF
    else
        strHeader = Join(arrHeader,",")
    end if
    CreateHeaderRow = strHeader
End Function
 
Function PopulateTableForCSV(CSVorTABLE)
    For intRow = LBound(arrRows) To UBound(arrRows)
        arrData = Split(arrRows(intRow), "|TD|")
        x = 0
        if chk_seatno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(0) & """"
            x = x + 1
        end if
        
        if chk_building.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(1) & """"
            x = x + 1
        end if
        
        if chk_extensionno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(2) & """"
            x = x + 1
        end if
        
        if chk_empid.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(3) & """"
            x = x + 1
        end if
        
        if chk_department.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(4) & """"
            x = x + 1
        end if
         
        if chk_designation.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(5) & """"
            x = x + 1
        end if
        
        if chk_name.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(6) & """"
            x = x + 1
        end if
        
        if chk_loginname.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(7) & """"
            x = x + 1
        end if
        
        if chk_email.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(8) & """"
            x = x + 1
        end if
        
        if chk_mailboxsize.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(25) & """"
            x = x + 1
        end if
        
        if chk_mailboxstore.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(26) & """"
            x = x + 1
        end if
        
        if chk_notes.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(9) & """"
            x = x + 1
        end if
        
        if chk_computerserialno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(23) & """"
            x = x + 1
        end if
        
        arrTemp = GetComputerInfo(arrData(9))
        if IsArray(arrTemp) then
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & GetOUPath(replace(arrTemp(0),"""","")) & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(1),"""","") & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(2),"""","") & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(4),"""","") & """"
                x = x + 1
            end if
	 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & replace(arrTemp(3),"""","") & """"
                x = x + 1
            end if
 
        else
 
            if chk_oupathcomputer.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computeros.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computerdescription.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
 
            if chk_computercreated.Checked then
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & """"
                x = x + 1
            end if
        end if
        
        if chk_mobileno.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(10) & """"
            x = x + 1
        end if
        
        if chk_company.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(11) & """"
            x = x + 1
        end if
        
        if chk_address.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(12) & """"
            x = x + 1
        end if
        
        if chk_city.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(13) & """"
            x = x + 1
        end if
        
        if chk_state.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(14) & """"
            x = x + 1
        end if
        
        if chk_zipcode.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(15) & """"
            x = x + 1
        end if
        
        if chk_country.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(16) & """"
            x = x + 1
        end if
        
        if chk_homephone.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(17) & """"
            x = x + 1
        end if
        
        if chk_manager.Checked then
            ReDim Preserve arrFileData(x)
            if arrData(18) <> "" then
                arrFileData(x) = """" & mid(arrData(18),4,instr(arrData(18),",")-4) & """"
            else
                arrFileData(x) = """" & """"
            end if
            x = x + 1
        end if
        
        if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
                
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
                
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
                
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = ""
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                ReDim Preserve arrFileData(x)
                arrFileData(x) = """" & str_subordinates & """"
                x = x + 1
            next
        end if
        
        if chk_whencreated.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(19) & """"
            x = x + 1
        end if
        
        if chk_oupathuser.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & GetOUPath(arrData(21)) & """"
            x = x + 1
        end if
        
        if chk_lastlogintimestamp.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & arrData(22) & """"
            x = x + 1
        end if
        
        if chk_groupmembership.Checked then
            ReDim Preserve arrFileData(x)
            arrFileData(x) = """" & ReportGroupMemberShipList(arrData(21), arrData(27)) & """"
            x = x + 1
        end if
 
        if CSVorTABLE <> "" then
            strFileData = strFileData & "<tr>"
            for n = 0 to UBound(arrFileData)-1
                strEntry = replace(arrFileData(n),"""","")
                if strEntry = "" then strEntry = "&nbsp;"
                strFileData = strFileData & "<td valign=""top"" align=""left"">" & strEntry & "</td>"
            next
            strFileData = strFileData & "</tr>" & vbCRLF
        else
            strFileData = strFileData & Join(arrFileData,",") & vbCRLF
        end if
    Next
    PopulateTableForCSV = strFileData
End Function 
 
Sub RunScript
      on error resume next
      Dim oDLG
      Set oDLG=CreateObject("MSComDlg.CommonDialog")
      if err.number > 0 then
          err.clear
          oDLG = window.prompt("Please enter the path and file name to save.", "D:\HTA-Result-Set.csv")
              if oDLG <> "" then
                  strAnswer = oDLG
              End If
      else
          With oDLG
              .DialogTitle = "Save As"
              .Filter="CSV File|*.csv"
              .MaxFileSize = 255
              .ShowSave
              If .FileName <> "" Then
                  strAnswer = .FileName
              End If
          End With
      end if
      Set oDLG=Nothing
 
      If IsNull(strAnswer) or strAnswer = "" Then
        'Do nothing
      Else
        if globalstrSearchBtnPush <> "" then
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            end if
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write CreateHeaderRow("") & vbCRLF
            objFile.Write PopulateTableForCSV("")
            objFile.Close
            MsgBox "Saved."
        else
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            If objFSO.FileExists(strAnswer) = True Then
                objFSO.DeleteFile strAnswer, True
            Else
                ' do nothing
            end if
 
            Set objFile = objFSO.CreateTextFile(strAnswer, True)
            objFile.Write """Security Groups""" & VbCrLf
            For Each objOption in lst_groupnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Write """Distribution Groups""" & VbCrLf
            For Each objOption in lst_dgnames.Options
                objFile.Write """" & objOption.Text & """" & VbCrLf
            Next
 
            objFile.Close
            MsgBox "Saved."
        End if
      End If
End Sub
 
Sub Email_This_Record
 
        ShowDialogTo
        ShowDialogCC
   
        ConvertNamesToEmailAddresses
	
	arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
	
        if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & txt_seatno.value & "<br>" & vbCRLF
	else
		str_seatno      = ""
	end if
 
        if chk_replacementseatno.Checked then
		str_replacementseatno      = "<b>These are the replacement details</b><br><b>Seat No: </b>" & txt_replacementseatno.value & "<br>" & vbCRLF
	else
		str_replacementseatno      = ""
	end if
 
	if chk_building.Checked then
		str_building    = "<b>Building: </b>" & txt_building.value &  "<br>" & vbCRLF
	else
		str_building    = ""
	end if
 
	if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & txt_extensionno.value &  "<br>" & vbCRLF
	else
		str_extensionno = ""
	end if
 
	if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & txt_empid.value &  "<br>" & vbCRLF
	else
		str_empid       = ""
	end if
 
	if chk_department.Checked then
		str_department  = "<b>Department: </b>" & txt_department.value &  "<br>" & vbCRLF
	else
		str_department  = ""
	end if
 
	if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & txt_designation.value &  "<br>" & vbCRLF
	else
		str_designation = ""
	end if
 
	if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & txt_name.value &  "<br>" & vbCRLF
	else
		str_name        = ""
	end if
 
	if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & txt_loginname.value &  "<br>" & vbCRLF
	else
		str_loginname   = ""
	end if
 
	if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & txt_email.value &  "<br>" & vbCRLF
	else
		str_email       = ""
	end if
 
	if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & txt_mailboxsize.value &  "<br>" & vbCRLF
	else
		str_mailboxsize       = ""
	end if
 
	if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & txt_mailboxstore.value &  "<br>" & vbCRLF
	else
		str_mailboxstore       = ""
	end if
 
	if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & txt_notes.value &  "<br>" & vbCRLF
	else
		str_notes       = ""
	end if
 
	if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & txt_computerserialno.value &  "<br>" & vbCRLF
	else
		str_computerserialno       = ""
	end if
 
	if chk_replacedmachine.Checked then
		str_replacedmachine       = "<b>These are the replacement details</b><br><b>Machine Name: </b>" & txt_replacedmachine.value &  "<br>" & vbCRLF
	else
		str_replacedmachine       = ""
	end if
 
	if chk_replacedcomputerserialno.Checked then
		str_replacedcomputerserialno       = "<b>Replaced Serial No: </b>" & txt_replacedcomputerserialno.value &  "<br>" & vbCRLF
	else
		str_replacedcomputerserialno       = ""
	end if
 
 
        arrTemp = GetComputerInfo(arrData(9))
 	if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & txt_oupathcomputer.value &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & txt_computeros.value &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & txt_computerservicepack.value &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & txt_computerdescription.value &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & txt_computercreated.value &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
	end if
 
	if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & txt_mobileno.value &  "<br>" & vbCRLF
	else
		str_mobileno    = ""
	end if
 
	if chk_company.Checked then
		str_company     = "<b>Company: </b>" & txt_company.value &  "<br>" & vbCRLF
	else
		str_company     = ""
	end if
 
	if chk_address.Checked then
		str_address     = "<b>Address: </b>" & txt_address.value &  "<br>" & vbCRLF
	else
		str_address     = ""
	end if
 
	if chk_city.Checked then
		str_city        = "<b>City: </b>" & txt_city.value &  "<br>" & vbCRLF
	else
		str_city        = ""
	end if
 
	if chk_state.Checked then
		str_state       = "<b>State: </b>" & txt_state.value &  "<br>" & vbCRLF
	else
		str_state       = ""
	end if
 
	if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & txt_zipcode.value &  "<br>" & vbCRLF
	else
		str_zipcode     = ""
	end if
 
	if chk_country.Checked then
		str_country     = "<b>Country: </b>" & txt_country.value &  "<br>" & vbCRLF
	else
		str_country     = ""
	end if
 
	if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & txt_homephone.value &  "<br>" & vbCRLF
	else
		str_homephone   = ""
	end if
 
	if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
	else
		str_manager   = ""
	end if
 
	if chk_subordinates.Checked then
            str_subordinates = "<b>Subordinates: </b>"
            boolFoundFirst = False
            str_subordinates = ""
            For Each objOption in lst_subordinates.Options
                if boolFoundFirst then
                    str_subordinates = str_subordinates & ", " & objOption.Text
                else
                    boolFoundFirst = True
                    str_subordinates = str_subordinates & objOption.Text
                end if
            Next
            str_subordinates = str_subordinates &  "<br>" & vbCRLF
	else
            str_subordinates = ""
	end if
  
	if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & txt_whencreated.value &  "<br>" & vbCRLF
	else
		str_whencreated = ""
	end if
  
	if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & txt_oupathuser.value &  "<br>" & vbCRLF
	else
		str_oupathuser       = ""
	end if
  
	if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & txt_lastlogintimestamp.value &  "<br>" & vbCRLF
	else
		str_lastlogintimestamp       = ""
	end if
 
	if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
	else
		str_groupmembership       = ""
	end if
 
        str_message = str_seatno & _
            str_replacementseatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_replacedmachine & _
            str_replacedcomputerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership
 
      if trim(txt_EmailSubject.value) = "" then
          strEmailSubject = "Active Directory Detail Report"
      else
          strEmailSubject = trim(txt_EmailSubject.value)
      end if
 
        Set objMessage = CreateObject("CDO.Message")
        objMessage.From = strEmailFrom
        objMessage.To = strEmailTo
        objMessage.CC = strEmailCC
        objMessage.BCC = strEmailBCC
        objMessage.Subject = strEmailSubject
        objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
        objMessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
        objMessage.Configuration.Fields.Update
        objMessage.Send
 
        MsgBox "An email has been sent"
 
End Sub
 
Sub Email_All_Records
 
    ShowDialogTo
    ShowDialogCC
   
    ConvertNamesToEmailAddresses
 
    str_message = ""
    if boolTableReports then
        str_message = str_message & "<table width=""100%"" border=""1"">" & vbCRLF
        str_message = str_message & CreateHeaderRow("Table") & vbCRLF
        str_message = str_message & PopulateTableForCSV("Table") & vbCRLF
        str_message = str_message & "</table>" & vbCRLF
    else
        for n = 0 to UBound(arrRows)
	    arrData = Split(arrRows(n), "|TD|")
 
            if chk_seatno.Checked then
		str_seatno      = "<b>Seat No: </b>" & arrData(0) &  "<br>" & vbCRLF
	    else
		str_seatno      = ""
            end if
 
            if chk_building.Checked then
		str_building    = "<b>Building: </b>" & arrData(1) &  "<br>" & vbCRLF
            else
		str_building    = ""
            end if
 
            if chk_extensionno.Checked then
		str_extensionno = "<b>Extension No: </b>" & arrData(2) &  "<br>" & vbCRLF
            else
		str_extensionno = ""
            end if
 
            if chk_empid.Checked then
		str_empid       = "<b>Emp ID: </b>" & arrData(3) &  "<br>" & vbCRLF
            else
		str_empid       = ""
            end if
 
            if chk_department.Checked then
		str_department  = "<b>Department: </b>" & arrData(4) &  "<br>" & vbCRLF
            else
		str_department  = ""
            end if
 
            if chk_designation.Checked then
		str_designation = "<b>Designation: </b>" & arrData(5) &  "<br>" & vbCRLF
            else
		str_designation = ""
            end if
 
            if chk_name.Checked then
		str_name        = "<b>User Name: </b>" & arrData(6) &  "<br>" & vbCRLF
            else
		str_name        = ""
            end if
 
            if chk_loginname.Checked then
		str_loginname   = "<b>Login Name: </b>" & arrData(7) &  "<br>" & vbCRLF
            else
		str_loginname   = ""
            end if
 
            if chk_email.Checked then
		str_email       = "<b>Email Address: </b>" & arrData(8) &  "<br>" & vbCRLF
            else
		str_email       = ""
            end if
 
            if chk_mailboxsize.Checked then
		str_mailboxsize       = "<b>Mailbox Size (MB): </b>" & arrData(25) &  "<br>" & vbCRLF
            else
		str_mailboxsize       = ""
            end if
 
            if chk_mailboxstore.Checked then
		str_mailboxstore       = "<b>Mailbox Store: </b>" & arrData(26) &  "<br>" & vbCRLF
            else
		str_mailboxstore       = ""
            end if
 
            if chk_notes.Checked then
		str_notes       = "<b>Machine Name: </b>" & arrData(9) &  "<br>" & vbCRLF
            else
		str_notes       = ""
            end if
 
            if chk_computerserialno.Checked then
		str_computerserialno       = "<b>Serial No: </b>" & arrData(23) &  "<br>" & vbCRLF
            else
		str_computerserialno       = ""
            end if
 
            arrTemp = GetComputerInfo(arrData(9))
            if IsArray(arrTemp) then
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" & GetOUPath(replace(arrTemp(0),"""","")) &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" & replace(arrTemp(1),"""","") &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" & replace(arrTemp(2),"""","") &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" & replace(arrTemp(4),"""","") &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" & replace(arrTemp(3),"""","") &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            else
		if chk_oupathcomputer.Checked then
			str_oupathcomputer       = "<b>OU Path - Computer: </b>" &  "<br>" & vbCRLF
		else
			str_oupathcomputer       = ""
		end if
 
		if chk_computeros.Checked then
			str_computeros       = "<b>Computer OS: </b>" &  "<br>" & vbCRLF
		else
			str_computeros       = ""
		end if
 
		if chk_computeros.Checked then
			str_computerservicepack       = "<b>Service Pack: </b>" &  "<br>" & vbCRLF
		else
			str_computerservicepack       = ""
		end if
 
		if chk_computerdescription.Checked then
			str_computerdescription       = "<b>Computer Description: </b>" &  "<br>" & vbCRLF
		else
			str_computerdescription       = ""
		end if
 
		if chk_computercreated.Checked then
			str_computercreated       = "<b>Computer Account Created: </b>" &  "<br>" & vbCRLF
		else
			str_computercreated       = ""
		end if
            end if
 
            if chk_mobileno.Checked then
		str_mobileno    = "<b>Mobile Number: </b>" & arrData(10) &  "<br>" & vbCRLF
            else
		str_mobileno    = ""
            end if
 
            if chk_company.Checked then
		str_company     = "<b>Company: </b>" & arrData(11) &  "<br>" & vbCRLF
            else
		str_company     = ""
            end if
 
            if chk_address.Checked then
		str_address     = "<b>Address: </b>" & arrData(12) &  "<br>" & vbCRLF
            else
		str_address     = ""
            end if
 
            if chk_city.Checked then
		str_city        = "<b>City: </b>" & arrData(13) &  "<br>" & vbCRLF
            else
		str_city        = ""
            end if
 
            if chk_state.Checked then
		str_state       = "<b>State: </b>" & arrData(14) &  "<br>" & vbCRLF
            else
		str_state       = ""
            end if
 
            if chk_zipcode.Checked then
		str_zipcode     = "<b>Zip Code: </b>" & arrData(15) &  "<br>" & vbCRLF
            else
		str_zipcode     = ""
            end if
 
            if chk_country.Checked then
		str_country     = "<b>Country: </b>" & arrData(16) &  "<br>" & vbCRLF
            else
		str_country     = ""
            end if
 
            if chk_homephone.Checked then
		str_homephone   = "<b>Home Phone: </b>" & arrData(17) &  "<br>" & vbCRLF
            else
		str_homephone   = ""
            end if
 
            if chk_manager.Checked then
		if arrData(18) <> "" then
	                str_manager   = "<b>Manager: </b>" & mid(arrData(18),4,instr(arrData(18),",")-4) &  "<br>" & vbCRLF
		else
			str_manager   = ""
		end if
            else
		str_manager   = ""
            end if
 
            if chk_subordinates.Checked then
            for each strDomain in arrDomainNames
                strSearchField = "(manager=" & arrData(21) & ")"
                strBase = "<LDAP://" & strDomain & ">"
                strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
                ' Comma delimited list of attribute values to retrieve.
                strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
   
                Set adoConnection = CreateObject("ADODB.Connection")
                Set adoCommand = CreateObject("ADODB.Command")
                adoConnection.Provider = "ADsDSOObject"
                adoConnection.Open "Active Directory Provider"
                Set adoCommand.ActiveConnection = adoConnection
                ' Construct the LDAP syntax query.
                strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
                adoCommand.CommandText = strQuery
                adoCommand.Properties("Page Size") = 100
                adoCommand.Properties("Timeout") = 30
                adoCommand.Properties("Cache Results") = False
    
                ' Run the query.
                Set adoRecordset = adoCommand.Execute
                boolFoundFirst = False
                str_subordinates = "<b>Subordinates: </b>"
                Do Until adoRecordset.EOF
                    strField = adoRecordset.Fields("cn").Value
                    if boolFoundFirst then
                        str_subordinates = str_subordinates & ", " & strField
                    else
                        boolFoundFirst = True
                        str_subordinates = str_subordinates & strField
                    end if
                    adoRecordset.MoveNext
                Loop
                str_subordinates = str_subordinates &  "<br>" & vbCRLF
            next
            else
		str_subordinates = ""
            end if
 
            if chk_whencreated.Checked then
		str_whencreated = "<b>Date Created: </b>" & arrData(19) &  "<br>" & vbCRLF
            else
		str_whencreated = ""
            end if
    
            if chk_oupathuser.Checked then
		str_oupathuser       = "<b>OU Path - User: </b>" & GetOUPath(arrData(21)) &  "<br>" & vbCRLF
            else
		str_oupathuser       = ""
            end if
    
            if chk_lastlogintimestamp.Checked then
		str_lastlogintimestamp       = "<b>Last Logon: </b>" & arrData(22) &  "<br>" & vbCRLF
            else
		str_lastlogintimestamp       = ""
            end if
  
 
            if chk_groupmembership.Checked then
		str_groupmembership       = "<b>Group Membership: </b>" & ReportGroupMemberShipList(arrData(21), arrData(27)) &  "<br>" & vbCRLF
            else
		str_groupmembership       = ""
            end if
 
            str_message = str_message & _
            str_seatno & _
            str_building & _
            str_extensionno & _
            str_empid & _
            str_department & _
            str_designation & _
            str_name & _
            str_loginname & _
            str_email & _
            str_mailboxsize & _
            str_mailboxstore & _
            str_notes & _
            str_computerserialno & _
            str_oupathcomputer & _
            str_computeros & _
            str_computerservicepack & _
            str_computerdescription & _
            str_computercreated & _
            str_mobileno & _
            str_company & _
            str_address & _
            str_city & _
            str_state & _
            str_zipcode & _
            str_country & _
            str_homephone & _
            str_manager & _
            str_subordinates & _
            str_whencreated & _
            str_oupathuser & _
            str_lastlogintimestamp & _
            str_groupmembership & VbCrLf & "<br><hr><br><br>" & vbCRLF
        next
    end if
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom 
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.HTMLBody = trim(txt_EmailBody.value) & "<br><br>" & vbCRLF & vbCRLF & str_message
            
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
      
    objMessage.Configuration.Fields.Update
    objMessage.Send
    
    MsgBox "An email has been sent"
    
End Sub
 
Sub Email_As_Attachment
    
    ShowDialogTo
    ShowDialogCC
    
    ConvertNamesToEmailAddresses
    
    strAnswer = fTemp & "\HTAResults.csv"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(strAnswer) = True Then
        objFSO.DeleteFile strAnswer, True
    end if
    Set objFile = objFSO.CreateTextFile(strAnswer, True)
    objFile.Write CreateHeaderRow("") & vbCRLF
    objFile.Write PopulateTableForCSV("")
    objFile.Close
    if trim(txt_EmailSubject.value) = "" then
        strEmailSubject = "Active Directory Detail Report"
    else
        strEmailSubject = trim(txt_EmailSubject.value)
    end if
    
    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = strEmailFrom
    objMessage.To = strEmailTo 
    objMessage.CC = strEmailCC
    objMessage.BCC = strEmailBCC
    objMessage.Subject = strEmailSubject
    objMessage.TextBody = trim(txt_EmailBody.value) & vbCRLF & vbCRLF
    
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strEmailServer
      
    objMessage.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    
    objMessage.Configuration.Fields.Update
    objMessage.AddAttachment strAnswer
    objMessage.Send
    
    MsgBox "An email has been sent"
    objFSO.DeleteFile strAnswer, True
    
End Sub
 
Sub SelectAllCheck
	If chk_selectall.Checked then
		CheckAllBoxes
                TestToSeeWhatLinesAreHidden
	else
		UnCheckAllBoxes
	end if
End Sub
 
Sub UnCheckAllBoxes
	chk_selectall.Checked = False
	chk_seatno.Checked = False
	chk_replacementseatno.Checked = False
	chk_building.Checked = False
	chk_extensionno.Checked = False
	chk_seatno.Checked = False
	chk_empid.Checked = False
	chk_department.Checked = False
	chk_designation.Checked = False
	chk_name.Checked = False
	chk_loginname.Checked = False
	chk_email.Checked = False
	chk_mailboxsize.Checked = False
	chk_mailboxstore.Checked = False
	chk_notes.Checked = False
	chk_computerserialno.Checked = False
	chk_replacedmachine.Checked = False
	chk_replacedcomputerserialno.Checked = False
	chk_oupathcomputer.Checked = False
	chk_computeros.Checked = False
	chk_computerdescription.Checked = False
	chk_computercreated.Checked = False
	chk_mobileno.Checked = False
	chk_company.Checked = False
	chk_address.Checked = False
	chk_city.Checked = False
	chk_state.Checked = False
	chk_zipcode.Checked = False
	chk_country.Checked = False
	chk_homephone.Checked = False
	chk_manager.Checked = False
	chk_whencreated.Checked = False
	chk_oupathuser.Checked = False
	chk_lastlogintimestamp.Checked = False
	chk_groupmembership.Checked = False
	chk_dgmembership.Checked = False
	chk_managerlist.Checked = False
	chk_subordinates.Checked = False
End Sub
 
Sub CheckAllBoxes
	chk_selectall.Checked = True
	chk_seatno.Checked = True
	chk_replacementseatno.Checked = True
	chk_building.Checked = True
	chk_extensionno.Checked = True
	chk_empid.Checked = True
	chk_department.Checked = True
	chk_designation.Checked = True
	chk_name.Checked = True
	chk_loginname.Checked = True
	chk_email.Checked = True
	chk_mailboxsize.Checked = True
	chk_mailboxstore.Checked = True
	chk_notes.Checked = True
	chk_computerserialno.Checked = True
	chk_replacedmachine.Checked = True
	chk_replacedcomputerserialno.Checked = True
	chk_oupathcomputer.Checked = True
	chk_computeros.Checked = True
	chk_computerdescription.Checked = True
	chk_computercreated.Checked = True
	chk_mobileno.Checked = True
	chk_company.Checked = True
	chk_address.Checked = True
	chk_city.Checked = True
	chk_state.Checked = True
	chk_zipcode.Checked = True
	chk_country.Checked = True
	chk_homephone.Checked = True
	chk_manager.Checked = True
	chk_whencreated.Checked = True
	chk_oupathuser.Checked = True
	chk_lastlogintimestamp.Checked = True
	chk_groupmembership.Checked = True
	chk_dgmembership.Checked = True
	chk_managerlist.Checked = True
	chk_subordinates.Checked = True
End Sub
 
Function GetUsersEmailAddress
	Set oNet = CreateObject("WScript.NetWork")
	sSearchField = "(samAccountName=*" & oNet.UserName & "*)"
	Set objRootDSE = GetObject("LDAP://RootDSE")
	sDNSDomain = objRootDSE.Get("defaultNamingContext")
	sBase = "<LDAP://" & sDNSDomain & ">"
	sFilter = "(&(objectCategory=person)(objectClass=user)" & sSearchField & ")"
	sAttributes = "cn,samAccountName,mail"
	sQuery = sBase & ";" & sFilter & ";" & sAttributes & ";subtree"
	Set aCommand = CreateObject("ADODB.Command")
	Set aConnection = CreateObject("ADODB.Connection")
	aConnection.Provider = "ADsDSOObject"
	aConnection.Open "Active Directory Provider"
	aCommand.ActiveConnection = aConnection
	aCommand.CommandText = sQuery
	aCommand.Properties("Page Size") = 100
	aCommand.Properties("Timeout") = 30
	aCommand.Properties("Cache Results") = False
	Set aRecordset = aCommand.Execute
 
	GetUsersEmailAddress = aRecordset.Fields("cn").Value
 
End Function
 
Sub ShowDialogCC
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailCC.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailCC.Value = strValidEmail
End Sub
 
Sub ShowDialogTo
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailTo.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailTo.Value = strValidEmail
End Sub
 
Sub ShowDialogFrom
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(txt_EmailFrom.Value,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("cn").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 0 then
                msgbox "The name """ & strResolve & """ could not be found.  The name has been removed from the field."
            end if
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
            if intCount > 1 then
                strSample = ShowModalDialog("modaldialog.hta",strResolve)
                strValidEmail = strValidEmail & strSample & ";"
            end if
        end if
    next
    txt_EmailFrom.Value = strValidEmail
End Sub
 
Sub FillGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    on error resume next
    
    Set objlst_groupnames = document.getElementById( "lst_groupnames" )
    objlst_groupnames.ListItems.Clear
    
    Set objlst_dgnames = document.getElementById( "lst_dgnames" )
    objlst_dgnames.ListItems.Clear
    
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
 
    ' This section is to pull group membership names
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
        strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
        strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
 
        if strLastGroupDN <> strdistinguishedName then
            Select Case strGroupType
                Case "[GDG]", "[LDG]", "[UDG]"
                    Set objListItem  = objlst_dgnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
                Case "[GSG]", "[LSG]", "[USG]"
                    Set objListItem  = objlst_groupnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
                Case "[Unknown]"
                    Set objListItem  = objlst_groupnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
            End Select
            strLastGroupDN = strdistinguishedName
        End if
        GroupMembershipDB.MoveNext
    Loop
    
    ' This section is to pull subordinate names
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoConnection = CreateObject("ADODB.Connection")
    Set adoCommand = CreateObject("ADODB.Command")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    Set adoCommand.ActiveConnection = adoConnection
 
    strSearchField = "(manager=" & usersDistinguishedname & ")"
    strBase = "<LDAP://" & strDNSDomain & ">"
    strFilter = "(&(objectCategory=person)(objectClass=user)" & strSearchField & ")"
            
    ' Comma delimited list of attribute values to retrieve.
    strAttributes = "cn,samAccountName,whenCreated,distinguishedName,userAccountControl"
    
    ' Construct the LDAP syntax query.
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    adoCommand.CommandText = strQuery
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False
 
    ' Run the query.
    Set adoRecordset = adoCommand.Execute
 
    Do Until adoRecordset.EOF
        set newOption = document.createElement("OPTION")
        newOption.Text = adoRecordset.Fields("cn").Value & " (" & GetSubordinateNumbers(adoRecordset.Fields("distinguishedName").Value) & ")"
        newOption.Value = adoRecordset.Fields("samAccountName").Value & ";" & adoRecordset.Fields("distinguishedName").Value
        lst_subordinates.Add newOption
        adoRecordset.MoveNext
        intsubordinates = intsubordinates + 1
    Loop
    
    span_groupmembership.InnerHTML = "(" & lst_groupnames.ListItems.Count & ")"
    span_dgmembership.InnerHTML    = "(" & lst_dgnames.ListItems.Count & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Function ReportGroupMembershipList(usersDistinguishedname,usersPrimaryGroupToken)
    GroupMembershipDB.Filter = "memberDistinguishedname = '" & usersDistinguishedname & "' OR PrimaryGroupToken = '" & usersPrimaryGroupToken & "'"
    GroupMembershipDB.Sort = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    strLastGroupDN = ""
    Do Until GroupMembershipDB.EOF
        strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
        if strLastGroupDN <> strdistinguishedName then
            strGroupType  = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName     = GroupMembershipDB.Fields.Item("samaccountname").Value
            strValue      = strValue & strNTName & " " & strGroupType & ";"
            strLastGroupDN = strdistinguishedName
            GroupMembershipDB.MoveNext
        End if
    Loop
    strValue = mid(strValue,1,len(strValue)-1)
    ReportGroupMembershipList = strValue
End Function
 
Function GetManagerDN(Manager)
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    
    strBase = "<LDAP://" & strDNSDomain & ">"
    
    strFilter = "(&(objectCategory=person)(objectClass=user)(cn=*" & Manager & "*))"
    
    strAttributes = "distinguishedName,CN"
    
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
    
    Set adoRecordset = CreateObject("ADODB.Recordset")
    adoRecordset.CursorLocation = 3
    adoRecordset.Sort = "distinguishedname"
    adoRecordset.Open strQuery, adoConnection, , , 1
    strresults = ""
    boolResultsFound = False
    Do Until adoRecordset.EOF
        strDN = adoRecordset.Fields("distinguishedName").Value
        sResults = sResults & "(manager=" & strDN & ")"
        boolResultsFound = True
        adoRecordset.MoveNext
    Loop
    if boolResultsFound then
        sResults = "(|" & sResults & ")"
    end if
    GetManagerDN = sResults
End Function
 
Sub FillGroupList
    Set objlst_groupnames = document.getElementById( "lst_groupnames" )
    objlst_groupnames.ListItems.Clear
 
    Set objlst_dgnames = document.getElementById( "lst_dgnames" )
    objlst_dgnames.ListItems.Clear
 
    For Each objOption in lst_subordinates.Options
        objOption.RemoveNode
    Next
    
    intGroupMembership = 0
    intdgmembership    = 0
    intsubordinates    = 0
    
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(objectCategory=group)"
        strAttributes = "sAMAccountName,primaryGroupToken,distinguishedName,samaccounttype,member"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "distinguishedname"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intNumberOfMembers = 0
            strNTName = adoRecordset.Fields("sAMAccountName").Value
            strPrimary = adoRecordset.Fields("primaryGroupToken").Value
            strdistinguishedName = adoRecordset.Fields("distinguishedName").Value
            strGroupType = GetSAMAccountType(adoRecordset.Fields("samaccounttype").Value)
            if NOT IsNull(adoRecordset.Fields("member").Value) then
                for each strMember in adoRecordset.Fields("member").Value
                    GroupMembershipDB.AddNew
                    GroupMembershipDB("sAMAccountName")          = strNTName
                    GroupMembershipDB("primaryGroupToken")       = strPrimary
                    GroupMembershipDB("distinguishedName")       = strdistinguishedName
                    GroupMembershipDB("samaccounttype")          = strGroupType
                    GroupMembershipDB("MemberDistinguishedName") = strMember
                    GroupMembershipDB.Update
                    intNumberOfMembers = intNumberOfMembers + 1
                next
            else
                GroupMembershipDB.AddNew
                GroupMembershipDB("sAMAccountName")          = strNTName
                GroupMembershipDB("primaryGroupToken")       = strPrimary
                GroupMembershipDB("distinguishedName")       = strdistinguishedName
                GroupMembershipDB("samaccounttype")          = strGroupType
                GroupMembershipDB("MemberDistinguishedName") = ""
                GroupMembershipDB.Update
            End if
            if NOT dicGroupNumbers.Exists(strdistinguishedName) then
                dicGroupNumbers.Add strdistinguishedName, intNumberOfMembers
                if strPrimary = 513 then
                    GetUsersWithPrimaryGroupID 513, strdistinguishedName
                    intNumberOfMembers = dicGroupNumbers.Item(strdistinguishedName)+1
                end if
            end if
            Select Case adoRecordset.Fields("samaccounttype").Value
                Case 2,268435457,4,536870913,8,268435457 'Distribution Groups
                    Set objListItem  = objlst_dgnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
                Case -2147483646,268435456,-2147483644,536870912,-2147483640,268435456 'Security Groups
                    Set objListItem  = objlst_groupnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
                Case Else
                    Set objListItem  = objlst_groupnames.ListItems.Add
                    objListItem.Text = strNTName
                    objListItem.ListSubItems.Add.Text = intNumberOfMembers
                    objListItem.ListSubItems.Add.Text = strGroupType
                    objListItem.ListSubItems.Add.Text = strdistinguishedName
                    objListItem.ListSubItems.Add.Text = strPrimary
            End Select
            
            adoRecordset.MoveNext
        Loop
    next
    
    span_groupmembership.InnerHTML = "(" & lst_groupnames.ListItems.Count & ")"
    span_dgmembership.InnerHTML    = "(" & lst_dgnames.ListItems.Count & ")"
    span_subordinates.InnerHTML    = "(" & intsubordinates & ")"
End Sub
 
Sub FillManagerList
    For Each objOption in lst_managerlist.Options
        objOption.RemoveNode
    Next
    intManagers = 0
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=*))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            strManager = adoRecordset.Fields("manager").Value
            if dicManagerList.Exists(strManager) then
                dicManagerList.Item(strManager) = dicManagerList.Item(strManager) + 1
            else
                dicManagerList.Add strManager, 1
                intManagers = intManagers + 1
            End if
            adoRecordset.MoveNext
        Loop
    next
    for each Manager in dicManagerList
        set newOption = document.createElement("OPTION")
        newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
        newOption.Value = Manager
        lst_managerlist.Add newOption
    next
    span_managerlist.InnerHTML = "(" & intManagers & ")"
End Sub
 
Sub PopulateManagerList
    For Each objOption in lst_managerlist.Options
        objOption.RemoveNode
    Next
    intManagers = 0
    for each Manager in dicManagerList
        set newOption = document.createElement("OPTION")
        newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
        newOption.Value = Manager
        lst_managerlist.Add newOption
        intManagers = intManagers + 1
    next
    span_managerlist.InnerHTML = "(" & intManagers & ")"
End Sub
 
Function GetSubordinateNumbers(manager)
    intSubordinates = 0
    for each strDomain in arrDomainNames
        Set adoCommand = CreateObject("ADODB.Command")
        Set adoConnection = CreateObject("ADODB.Connection")
        adoConnection.Provider = "ADsDSOObject"
        adoConnection.Open "Active Directory Provider"
        adoCommand.ActiveConnection = adoConnection
        strBase = "<LDAP://" & strDomain & ">"        
        strFilter = "(&(objectCategory=user)(manager=" & manager & "))"
        strAttributes = "manager"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        Set adoRecordset = CreateObject("ADODB.Recordset")
        adoRecordset.CursorLocation = 3
        adoRecordset.Sort = "manager"
        adoRecordset.Open strQuery, adoConnection, , , 1
        Do Until adoRecordset.EOF
            intSubordinates = intSubordinates + 1
            adoRecordset.MoveNext
        Loop
    next
    GetSubordinateNumbers = intSubordinates
End FUnction
 
Function GetSAMAccountType(SAMAccountType)
    Select Case SAMAccountType
        Case 2, 268435457
            GetSAMAccountType = "[GDG]" 'This is a global distribution group
        Case 4, 536870913
            GetSAMAccountType = "[LDG]" 'This is a domain local distribution group
        Case 8, 268435457
            GetSAMAccountType = "[UDG]" 'This is a universal distribution group
        Case -2147483646, 268435456
            GetSAMAccountType = "[GSG]" 'This is a global security group
        Case -2147483644, 536870912
            GetSAMAccountType = "[LSG]" 'This is a domain local security group
        Case -2147483640, 268435456
            GetSAMAccountType = "[USG]" 'This is a universal security group
        Case Else
            GetSAMAccountType = "[Unknown]" 'This is an unknown group type
    End Select
End Function
 
Sub GetUsersWithPrimaryGroupID(PrimaryGroupID,distinguishedName)
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    strSearchField = "(primaryGroupID=" & PrimaryGroupID & ")"
    for each strDomain in arrDomainNames
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=user)(objectCategory=contact)" & strSearchField & ")"
        strAttributes = "cn,primaryGroupID"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 100
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        Set adoRecordset = adoCommand.Execute
        If Not adoRecordset.EOF Then
            Do Until adoRecordset.EOF
                n = n + 1
                adoRecordset.movenext
            Loop
        End If
    next
    dicGroupNumbers.Item(distinguishedName) = n
End Sub
 
Sub FillSubjectList
    For Each objOption in txt_EmailSubject.Options
        objOption.RemoveNode
    Next
    For each strSubjectlineText in arrSubjectText
        set newOption = document.createElement("OPTION")
        newOption.Text = strSubjectlineText
        newOption.Value = strSubjectlineText
        txt_EmailSubject.Add newOption
    Next
End Sub
 
Sub ConvertNamesToEmailAddresses
    txt_EmailToHidden.Value = GetEmailAddresses(txt_EmailTo.Value)
    txt_EmailCCHidden.Value = GetEmailAddresses(txt_EmailCC.Value)
    strEmailTo = txt_EmailToHidden.Value
End Sub
 
Function GetEmailAddresses(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidEmail = ""
 
    arrResolve = split(names,";")
 
    for each strResolve in arrResolve
        strResolve = trim(strResolve)
        if instr(strResolve,"@") then
            'Treat as valid email address
            strValidEmail = strValidEmail & strResolve & ";"
        elseif strResolve <> "" then
 
            Set objRoot = GetObject("LDAP://rootDSE")
            strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
 
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
 
            Set objCommand.ActiveConnection = objConnection
            objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=person)" & _
             "(mail=*)(cn=*" & strResolve & "*));cn,samAccountName,mail;subtree"
 
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Timeout") = 90
            objCommand.Properties("Cache Results") = False
    
            Set objRecordSet1 = objCommand.Execute
            intCount = 0
            While Not objRecordSet1.EOF
                intCount = intCount + 1
                strFullName = objRecordSet1.Fields("mail").Value
                objRecordSet1.MoveNext
            Wend 
 
            if intCount = 1 then
                strValidEmail = strValidEmail & strFullName & ";"
            end if
        end if
    next
    GetEmailAddresses = strValidEmail
End Function
 
Function GetOUPath(OU)
    strOU = ""
    strFQDN = ""
    boolFoundMatch = False
    arrValues = split(OU,",")
    for each strValue in arrValues
        if instr(strValue,"OU=") then
            strOU = strOU & replace(strValue,"OU=","") & "\"
        end if
        if instr(strValue,"DC=") then
            strFQDN = strFQDN & replace(strValue,"DC=","") & "."
        end if
        if instr(strValue,"CN=") then
            if boolFoundMatch then
                strCN = strCN & replace(strValue,"CN=","") & "\"
            else
                'Skip the first match - this is always the user name
                boolFoundMatch = True
            end if
        end if
    next
    if strFQDN <> "" then
        strFQDN = left(strFQDN,len(strFQDN)-1)
        if strOU <> "" then
            strOU = left(strOU,len(strOU)-1)
        else
            'strOU = "{object not found in any OU}"
            if strCN <> "" then
                strOU = left(strCN,len(strCN)-1)
            end if
        end if
        GetOUPath = (Split(strOU,"\")(0))
    else
        GetOUPath = ""
    end if
End Function
 
Function GetComputerInfo(names)
    Const adVarChar = 200
    Const MaxCharacters = 255
 
    strValidComputer = ""
 
    strResolve = trim(names)
 
    if strResolve <> "" then
        Set objRoot = GetObject("LDAP://rootDSE")
        strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
 
        Set objConnection = CreateObject("ADODB.Connection")
        Set objCommand = CreateObject("ADODB.Command")
 
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open "Active Directory Provider"
 
        Set objCommand.ActiveConnection = objConnection
        objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _
        "(cn=" & strResolve & "));cn,samAccountName,distinguishedName,operatingsystem,operatingsystemservicepack,whencreated,description;subtree"
 
        objCommand.Properties("Page Size") = 1000
        objCommand.Properties("Timeout") = 90
        objCommand.Properties("Cache Results") = False
    
        Set objRecordSet1 = objCommand.Execute
 
        While Not objRecordSet1.EOF
 
            if IsNull(objRecordSet1.Fields("distinguishedName").Value) then
                sDN = ""
            else
                sDN = replace(objRecordSet1.Fields("distinguishedName").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystem").Value) then
                sOS = ""
            else
                sOS = replace(objRecordSet1.Fields("operatingsystem").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("operatingsystemservicepack").Value) then
                sSP = ""
            else
                sSP = replace(objRecordSet1.Fields("operatingsystemservicepack").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("whencreated").Value) then
                sWC = ""
            else
                sWC = replace(objRecordSet1.Fields("whencreated").Value,vbCRLF,"")
            End if
 
            if IsNull(objRecordSet1.Fields("description").Value) then
                sDS = ""
            else
                sDS = join(objRecordSet1.Fields("description").Value)
                sDS = replace(sDS,vbCRLF,"")
            End if
 
            strValidComputer = Array("""" & sDN & """","""" & sOS & """","""" & sSP & """","""" & sWC & """","""" & sDS & """")
            objRecordSet1.MoveNext
        Wend 
    end if
 
    if isArray(strValidComputer) then
        GetComputerInfo = strValidComputer
    else
        GetComputerInfo = ""
    end if
End Function
 
Sub ShowSubMenu(Parent,Child)
    If Child.style.display="block" Then
        Parent.classname="Menuover"
        Child.style.display="none"
        Set LastChildMenu=Nothing
    Else
        Parent.classname="Menuin"
        Child.style.display="block"
        Set LastChildMenu=Child
    End If
    Set LastMenu=Parent
End Sub
 
Sub MenuOver(Parent,Child)
    If LastChildMenu is Nothing Then
        Parent.className="MenuOver"
    Else
        If LastMenu is Parent Then
            Parent.className="MenuIn"
        Else
            HideMenu
            ShowSubMenu Parent,Child
        End If
    End If
End Sub
 
Sub MenuOut(Menu)
    If LastChildMenu is Nothing Then Menu.className="MenuOut"
End Sub
 
Sub HideMenu
    If Not LastChildMenu is Nothing Then
        LastChildMenu.style.display="none"
        Set LastChildMenu=Nothing
        LastMenu.classname="Menuout"
    End If
End Sub
 
Sub SubMenuOver(Menu)
    Menu.className="SubMenuOver"
End Sub
 
Sub SubMenuOut(Menu)
    Menu.className="SubMenuOut"
End Sub
 
Sub SaveAs
    on error resume next
    Dim oDLG
    Set oDLG=CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to save.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            Save
        End If
    else
        With oDLG
            .DialogTitle = "Save As"
            .Filter="Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .ShowSave
            If .FileName <> "" Then
                FileName = .FileName
                Save
            End If
        End With
    end if
    Set oDLG=Nothing
    DisplayTitle
End Sub
 
Sub Save()
    Dim fso,f
    If FileName <> "" Then
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f = fso.CreateTextFile(FileName,True)
        
        'This is the text to get saved into the file
        with f
            .writeline "<root>"
            .writeline "<searchfield>" & globalStrSearchField & "</searchfield>"
            .writeline "<btnpush>" & globalStrSearchBtnPush & "</btnpush>"
            .writeline "<to>" & txt_EmailTo.value & "</to>"
            .writeline "<cc>" & txt_EmailCC.value & "</cc>"
            .writeline "<bcc>" & strEmailBCC & "</bcc>"
            .writeline "<subject>" & txt_EmailSubject.value & "</subject>"
            .writeline "<emailbody>" & txt_EmailBody.value & "</emailbody>"
            if chk_selectall.Checked then .writeline "<checkboxes>chk_selectall</checkboxes>"
            if chk_seatno.Checked then .writeline "<checkboxes>chk_seatno</checkboxes>"
            if chk_building.Checked then .writeline "<checkboxes>chk_building</checkboxes>"
            if chk_extensionno.Checked then .writeline "<checkboxes>chk_extensionno</checkboxes>"
            if chk_empid.Checked then .writeline "<checkboxes>chk_empid</checkboxes>"
            if chk_department.Checked then .writeline "<checkboxes>chk_department</checkboxes>"
            if chk_designation.Checked then  .writeline "<checkboxes>chk_designation</checkboxes>"
            if chk_name.Checked then .writeline "<checkboxes>chk_name</checkboxes>"
            if chk_loginname.Checked then .writeline "<checkboxes>chk_loginname</checkboxes>"
            if chk_email.Checked then .writeline "<checkboxes>chk_email</checkboxes>"
            if chk_mailboxsize.Checked then .writeline "<checkboxes>chk_mailboxsize</checkboxes>"
            if chk_mailboxstore.Checked then .writeline "<checkboxes>chk_mailboxstore</checkboxes>"
            if chk_notes.Checked then .writeline "<checkboxes>chk_notes</checkboxes>"
            if chk_computerserialno.Checked then .writeline "<checkboxes>chk_computerserialno</checkboxes>"
            if chk_replacedmachine.Checked then .writeline "<checkboxes>chk_replacedmachine</checkboxes>"
            if chk_replacedcomputerserialno.Checked then .writeline "<checkboxes>chk_replacedcomputerserialno</checkboxes>"
            if chk_oupathcomputer.Checked then .writeline "<checkboxes>chk_oupathcomputer</checkboxes>"
            if chk_computeros.Checked then .writeline "<checkboxes>chk_computeros</checkboxes>"
            if chk_computerdescription.Checked then .writeline "<checkboxes>chk_computerdescription</checkboxes>"
            if chk_computercreated.Checked then  .writeline "<checkboxes>chk_computercreated</checkboxes>"
            if chk_mobileno.Checked then  .writeline "<checkboxes>chk_mobileno</checkboxes>"
            if chk_company.Checked then .writeline "<checkboxes>chk_company</checkboxes>"
            if chk_address.Checked then  .writeline "<checkboxes>chk_address</checkboxes>"
            if chk_city.Checked then .writeline "<checkboxes>chk_city</checkboxes>"
            if chk_state.Checked then .writeline "<checkboxes>chk_state</checkboxes>"
            if chk_zipcode.Checked then .writeline "<checkboxes>chk_zipcode</checkboxes>"
            if chk_country.Checked then .writeline "<checkboxes>chk_country</checkboxes>"
            if chk_homephone.Checked then .writeline "<checkboxes>chk_homephone</checkboxes>"
            if chk_manager.Checked then .writeline "<checkboxes>chk_manager</checkboxes>"
            if chk_whencreated.Checked then .writeline "<checkboxes>chk_whencreated</checkboxes>"
            if chk_oupathuser.Checked then .writeline "<checkboxes>chk_oupathuser</checkboxes>"
            if chk_lastlogintimestamp.Checked then .writeline "<checkboxes>chk_lastlogintimestamp</checkboxes>"
            if chk_groupmembership.Checked then .writeline "<checkboxes>chk_groupmembership</checkboxes>"
            if chk_dgmembership.Checked then .writeline "<checkboxes>chk_dgmembership</checkboxes>"
            if chk_managerlist.Checked then .writeline "<checkboxes>chk_managerlist</checkboxes>"
            if chk_subordinates.Checked then .writeline "<checkboxes>chk_subordinates</checkboxes>"
            .writeline "</root>"
            .Close
        end with
        
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        XmlDom.async = False
        XmlDom.Load(FileName)
        xmlDom.Save(FileName)
        
        Set f = Nothing
        Set fso = Nothing
    Else
        SaveAs
    End If
End Sub
 
Sub OpenIt
    UnCheckAllBoxes
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    xmlDom.load(FileName)
    
    globalStrSearchField = xmlDom.getElementsByTagName("searchfield").item(0).text
    globalStrSearchBtnPush = xmlDom.getElementsByTagName("btnpush").item(0).text
    txt_EmailTo.value = xmlDom.getElementsByTagName("to").item(0).text
    txt_EmailCC.value = xmlDom.getElementsByTagName("cc").item(0).text
    strEmailBCC = xmlDom.getElementsByTagName("bcc").item(0).text
    txt_EmailSubject.value = xmlDom.getElementsByTagName("subject").item(0).text
    txt_EmailBody.value = xmlDom.getElementsByTagName("emailbody").item(0).text
    
    for n = 0 to xmlDom.getElementsByTagName("checkboxes").Length-1
        execute(xmlDom.getElementsByTagName("checkboxes").item(n).text & ".checked = True")
    next
    
    DisplayTitle
    
    Submit_Form "FileOpen"
End Sub
 
Sub Open()
    on error resume next
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "C:\your-query.qry")
        if oDLG <> "" then
            FileName = oDLG
            OpenIt
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Query|*.qry|Text Files|*.txt|All files|*.*"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                FileName = .FileName
                OpenIt
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub DisplayTitle
    If FileName="" Then
        document.Title="Default - " & oHTA.ApplicationName
    Else
        document.Title=FileName & " - " & oHTA.ApplicationName
    End If
End Sub
 
Sub ClickTheSpecialReportButton
    Submit_Form("Disabled")
End Sub
 
Sub SpecialReportNewUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("Main")
End Sub
 
Sub SpecialReportDisabledUsersToday
    Clear_Form ""
    txt_whencreated.Value = FormatDateTime(Date(),2)
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub SpecialReportDisabledUsersSomeDay
    Clear_Form ""
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    txt_whencreated.value = sRtn
    Detect_Search_Field("txt_whencreated")
    Submit_Form("DisabledToday")
End Sub
 
Sub GetChkProfiles 
    For Each objOption in lst_ChkProfiles.Options
        objOption.RemoveNode
    Next
    
    strAnswer = fAppData & "\profile.xml"
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If NOT objFSO.FileExists(strAnswer) Then
        'Create profile.xml
	Set f = objFSO.CreateTextFile(strAnswer,True)
        with f
            .writeline "<root>"
            .writeline "<profile val=""Default"">"
            .writeline "<checkboxes val=""chk_selectall"" />"
            .writeline "<checkboxes val=""chk_seatno"" />"
            .writeline "<checkboxes val=""chk_replacementseatno"" />"
            .writeline "<checkboxes val=""chk_building"" />"
            .writeline "<checkboxes val=""chk_extensionno"" />"
            .writeline "<checkboxes val=""chk_empid"" />"
            .writeline "<checkboxes val=""chk_department"" />"
            .writeline "<checkboxes val=""chk_designation"" />"
            .writeline "<checkboxes val=""chk_name"" />"
            .writeline "<checkboxes val=""chk_loginname"" />"
            .writeline "<checkboxes val=""chk_email"" />"
            .writeline "<checkboxes val=""chk_mailboxsize"" />"
            .writeline "<checkboxes val=""chk_mailboxstore"" />"
            .writeline "<checkboxes val=""chk_notes"" />"
            .writeline "<checkboxes val=""chk_computerserialno"" />"
            .writeline "<checkboxes val=""chk_replacedmachine"" />"
            .writeline "<checkboxes val=""chk_replacedcomputerserialno"" />"
            .writeline "<checkboxes val=""chk_oupathcomputer"" />"
            .writeline "<checkboxes val=""chk_computeros"" />"
            .writeline "<checkboxes val=""chk_computerdescription"" />"
            .writeline "<checkboxes val=""chk_computercreated"" />"
            .writeline "<checkboxes val=""chk_mobileno"" />"
            .writeline "<checkboxes val=""chk_company"" />"
            .writeline "<checkboxes val=""chk_address"" />"
            .writeline "<checkboxes val=""chk_city"" />"
            .writeline "<checkboxes val=""chk_state"" />"
            .writeline "<checkboxes val=""chk_zipcode"" />"
            .writeline "<checkboxes val=""chk_country"" />"
            .writeline "<checkboxes val=""chk_homephone"" />"
            .writeline "<checkboxes val=""chk_manager"" />"
            .writeline "<checkboxes val=""chk_whencreated"" />"
            .writeline "<checkboxes val=""chk_oupathuser"" />"
            .writeline "<checkboxes val=""chk_lastlogintimestamp"" />"
            .writeline "<checkboxes val=""chk_groupmembership"" />"
            .writeline "<checkboxes val=""chk_dgmembership"" />"
            .writeline "<checkboxes val=""chk_managerlist"" />"
            .writeline "<checkboxes val=""chk_subordinates"" />"
            .writeline "</profile>"
            .writeline "</root>"
            .Close
	end with
 
	Set xmlDom = CreateObject("Microsoft.XMLDOM")
	XmlDom.async = False
	XmlDom.Load(strAnswer)
	xmlDom.Save(strAnswer)
    End If
 
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile")
    
    for n = 0 to oNodes.length - 1
        set newOption = document.createElement("OPTION")
        newOption.Text = oNodes(n).selectSingleNode("@val").Text
        newOption.Value = oNodes(n).selectSingleNode("@val").Text
        lst_ChkProfiles.Add newOption
    next
 
    Set f = Nothing
    Set objFSO = Nothing
End Sub
 
Sub lst_chkprofiles_OnChange
 
    UnCheckAllBoxes
 
    strAnswer = fAppData & "\profile.xml"
    
    Set xmlDom = CreateObject("Microsoft.XMLDOM")
    xmlDom.async="false"
    XmlDom.Load(strAnswer)
 
    Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]/checkboxes")   
 
    For i = 0 To oNodes.length - 1
        execute(oNodes(i).selectSingleNode("@val").Text & ".Checked = True")
    Next
 
    TestToSeeWhatLinesAreHidden
End Sub
 
Sub DeleteFromCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        For Each objOption in lst_chkprofiles.Options
            If objOption.Value = lst_chkprofiles.Value Then
                objOption.RemoveNode
            End If
        Next
        msgbox "Checkbox profile deleted."
        lst_chkprofiles_OnChange
    else
        msgbox "You cannot delete the default profile."
    end if
End Sub
 
Sub ModifyCurrentCheckboxProfile
    if lst_chkprofiles.Value <> "Default" then
        strAnswer = fAppData & "\profile.xml"
        Set xmlDom = CreateObject("Microsoft.XMLDOM")
        xmlDom.async="false"
        XmlDom.Load(strAnswer)
        strProfileName = lst_chkprofiles.Value
        Set oNodes = XmlDom.selectNodes("//profile[@val=""" & lst_chkprofiles.Value & """]")
        For Each objNode in oNodes
            xmlDom.documentElement.removeChild _
                (objNode)
        Next
        XmlDom.Save(strAnswer)
        
        Const ForReading = 1
        Const ForWriting = 2
     
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
     
        Do Until objFile.AtEndOfStream
            strLine = objFile.Readline
            strLine = Trim(strLine)
            If strLine <> "</root>" Then
                strContents = strContents & strLine & vbCrLf
            End If
        Loop
     
        objFile.Close
        
        Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
        
        with f
            .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
            if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
            if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
            if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
            if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
            if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
            if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
            if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
            if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
            if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
            if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
            if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
            if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
            if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
            if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
            if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
            if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
            if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
            if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
            if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
            if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
            if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
            if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
            if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
            if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
            if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
            if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
            if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
            if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
            if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
            if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
            if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
            if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
            if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
            if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
            if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
            if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
            if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
            .writeline vbTab & "</profile>"
            .writeline "</root>"
            .close
        end with
        
        msgbox "Checkbox profile modified."
    else
        msgbox "You cannot modify the default profile."
    end if
End Sub
 
Sub AddToCheckboxProfile
    strProfileName = window.prompt("Please enter a profile name.", "My profile name")
    strAnswer = fAppData & "\profile.xml"
 
    Const ForReading = 1
    Const ForWriting = 2
 
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strAnswer, ForReading)
 
    Do Until objFile.AtEndOfStream
        strLine = objFile.Readline
        strLine = Trim(strLine)
        If strLine <> "</root>" Then
            strContents = strContents & strLine & vbCrLf
        End If
    Loop
 
    objFile.Close
    
    Set f = objFSO.OpenTextFile(strAnswer, ForWriting)
    
    with f
        .writeline strContents & vbTab & "<profile val=""" & strProfileName & """>"
	if chk_selectall.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_selectall"" />"
	if chk_seatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_seatno"" />"
        if chk_replacementseatno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacementseatno"" />"
	if chk_building.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_building"" />"
	if chk_extensionno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_extensionno"" />"
	if chk_empid.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_empid"" />"
	if chk_department.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_department"" />"
	if chk_designation.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_designation"" />"
	if chk_name.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_name"" />"
	if chk_loginname.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_loginname"" />"
	if chk_email.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_email"" />"
	if chk_mailboxsize.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxsize"" />"
	if chk_mailboxstore.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mailboxstore"" />"
	if chk_notes.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_notes"" />"
	if chk_computerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerserialno"" />"
	if chk_replacedmachine.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedmachine"" />"
	if chk_replacedcomputerserialno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_replacedcomputerserialno"" />"
	if chk_oupathcomputer.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathcomputer"" />"
	if chk_computeros.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computeros"" />"
	if chk_computerdescription.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computerdescription"" />"
	if chk_computercreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_computercreated"" />"
	if chk_mobileno.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_mobileno"" />"
	if chk_company.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_company"" />"
	if chk_address.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_address"" />"
	if chk_city.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_city"" />"
	if chk_state.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_state"" />"
	if chk_zipcode.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_zipcode"" />"
	if chk_country.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_country"" />"
	if chk_homephone.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_homephone"" />"
	if chk_manager.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_manager"" />"
	if chk_whencreated.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_whencreated"" />"
	if chk_oupathuser.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_oupathuser"" />"
	if chk_lastlogintimestamp.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_lastlogintimestamp"" />"
	if chk_groupmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_groupmembership"" />"
	if chk_dgmembership.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_dgmembership"" />"
	if chk_managerlist.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_managerlist"" />"
	if chk_subordinates.checked then .writeline vbTab & vbTab & "<checkboxes val=""chk_subordinates"" />"
	.writeline vbTab & "</profile>"
	.writeline "</root>"
        .close
    end with
 
    set newOption = document.createElement("OPTION")
    newOption.Text = strProfileName
    newOption.Value = strProfileName
    lst_ChkProfiles.Add newOption
 
    lst_ChkProfiles.Value = strProfileName
End Sub
 
Sub AddToQueryBuilder
	globalstrQueryBuilder = globalstrQueryBuilder & globalstrSearchField
	if NOT chk_qbrecorder.Checked then
		msgbox "The query has been added."
	end if
End Sub
 
Sub QueryBuilderRecorder
    if chk_qbrecorder.Checked then
        msgbox "Query Builder is now recording."
    else
        msgbox "Query Builder has stopped recording." & vbCrLf & "Click OK to view the combined query."
        RunQueryBuilder
    end if
End Sub
 
Sub ViewQueryBuilder
    if globalstrQueryBuilder <> "" then
        msgbox "(|" & globalstrQueryBuilder & ")"
    else
        msgbox "There are no stored queries to view."
    end if
End Sub
 
Sub RunQueryBuilder
    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
    globalstrSearchBtnPush = "FileOpen"
    Submit_Form "FileOpen"
End Sub
 
Sub ClearQueryBuilder
    globalstrQueryBuilder = ""
End Sub
 
Sub txt_EmailSubject_OnChange
    For i = 0 to (txt_EmailSubject.Options.Length - 1)
        If (txt_EmailSubject.Options(i).Selected) Then
            strEmailTo          = arrToSpecial(i)
            strEmailCC          = arrCCSpecial(i)
            strEmailBody        = arrBodySpecial(i)
            strCheckBoxProfile  = arrCheckBoxSpecial(i)
            txt_EmailTo.Value   = strEmailTo
            txt_EmailCC.Value   = strEmailCC
            txt_EmailBody.Value = strEmailBody
            For Each objOption in lst_chkprofiles.Options
                If objOption.Value = strCheckBoxProfile Then
                    objOption.Selected = True
                    lst_chkprofiles_OnChange
                End If
            Next
        End If
    Next
End Sub
 
Sub PingComputer(name)
    if name <> "" then
        strComuptername = trim(name)
        'Run PING command
        Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
        'Take ping reults and put into variable strPingResult 
        strPingResult = 0
        For Each oPingResult In objPingResults
            strPingResult = oPingResult.ResponseTime
            strIPAddress  = oPingResult.ProtocolAddress
        Next
        'Catch PINGS that do not have a result - typically this is for unreachable devices
        if IsEmpty(strPingResult) then
            strPingResult = 9999
        end if
        if IsNULL(strPingResult) then
            strPingResult = 9999
        end if
        ' Run ping again if first attempt fails
        if strPingResult = 9999 then
            'Run PING command
            Set objPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComuptername & "'")
            'Take ping reults and put into variable strPingResult 
            strPingResult = 0
            For Each oPingResult In objPingResults
                strPingResult = oPingResult.ResponseTime
                strIPAddress  = oPingResult.ProtocolAddress
            Next
            'Catch PINGS that do not have a result - typically this is for unreachable devices
            if IsEmpty(strPingResult) then
                strPingResult = 9999
            end if
            if IsNULL(strPingResult) then
                strPingResult = 9999
            end if
        end if
        span_computerip.innerhtml = strIPAddress
        if strPingResult = 9999 then
            span_computeronline.innerhtml = "Offline"
        else
            span_computeronline.innerhtml = "Online"
        end if
    else
        span_computerip.innerhtml = " "
        span_computeronline.innerhtml = " "
    end if
End Sub
 
Sub bt2Go_onclick()
 
    '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, DENY, POS, NEG
    Dim objNetwork, objShell
 
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Write username for the user that needs to be enabled or disabled:'
    USR = InputBox("Username:", "Enable or Disable Active Directory User", _
    "Write Username Here")
     
    if USR = "" then
	exit sub
    End if
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** Declare NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate name into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
    '** Do LDAP bind to object:'
    Set objUser = GetObject("LDAP://" & strUserDN)
     
    '** Get full name:'
    strUS1 = Mid(strUserDN,4)
    strUS2 = Split(strUS1, ",")
    For i = LBound(strUS2) to UBound(strUS2)
        strNM = strUS2(i)
        Exit For
    Next
 
    '** If no error, enable or disable user:'
    If Err = 0 Then
        Const ADS_UF_ACCOUNTDISABLE = 2
        intUAC = objUser.Get("userAccountControl")
        objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
        objUser.SetInfo
        If intUAC AND ADS_UF_ACCOUNTDISABLE Then
            POS = 1
        Else
            NEG = 1
        End If
    Else
        objShell.Popup UCase(USR) & " was not found. Please try again.", _
        5, "Unknown Username", 48
        exit sub
    End If
 
    '** If no permission, give message:'
    If Err = "-2147024891" Then
        DENY = 1
        objShell.Popup "You can not enable or disable this user.", _
        5, "Permission Denied", 48
        exit sub
    End If
 
    '** If no error, show result:'
    If DENY <> 1 Then
        If POS = 1 Then
            MsgBox UCase(USR) & " were successfully enabled.", _
            64, "User enabled by " & strNM2
        End If
 
        If NEG = 1 Then
            MsgBox UCase(USR) & " were successfully disabled.", _
            64, "User disabled by " & strNM2
        End If
    End If
End Sub
 
Sub bt1Go_onclick()
     '** Declarations:'
    Dim OPR, DM, USR, strNTName, strUserDN, strNM, objUser, TNP, EROR, ABS
    Dim objNetwork, objShell, objFSO
     
    '** Objects:'
    Set objNetwork = CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     
    '** User/Domain:'
    OPR = objNetwork.UserName
    DM = objNetwork.UserDomain & "\"
     
    '** Type username for the user that needs password change:'
    USR = InputBox("Username:", "Create Temporary Active Directory User Password", _
    "Write Username Here")
     
    if USR = "" then
        exit sub
    End if
 
    '** Prevent run-time errors:'
    On Error Resume Next
     
    '** NameTranslate constants:'
    Const ADS_NAME_INITTYPE_GC = 3
    Const ADS_NAME_TYPE_NT4 = 3
    Const ADS_NAME_TYPE_1779 = 1
     
    '** Combine the user name and domain name:'
    strNTName = DM & USR
    strNT2 = DM & OPR
     
    '** Translate operator name into DN:'
    Set objTrans2 = CreateObject("NameTranslate")
    objTrans2.Init ADS_NAME_INITTYPE_GC, ""
    objTrans2.Set ADS_NAME_TYPE_NT4, strNT2
    strUserDN2 = objTrans2.Get(ADS_NAME_TYPE_1779)
    Set objUser2 = GetObject("LDAP://" & strUserDN2)
    strUS3 = Mid(strUserDN2,4)
    strUS4 = Split(strUS3, ",")
    For i = LBound(strUS4) to UBound(strUS4)
        strNM2 = strUS4(i)
        Exit For
    Next
 
    '** Translate username into DN:'
    Set objTrans = CreateObject("NameTranslate")
    objTrans.Init ADS_NAME_INITTYPE_GC, ""
    objTrans.Set ADS_NAME_TYPE_NT4, strNTName
    If Err <> 0 Then
        ABS = 1
    End If
     
    '** Execute if object is found:'
    If ABS <> 1 Then
        strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
        '** Do LDAP bind to object:'
        Set objUser = GetObject("LDAP://" & strUserDN)
     
        '** Get full name:'
        strUS1 = Mid(strUserDN,4)
        strUS2 = Split(strUS1, ",")
        For i = LBound(strUS2) to UBound(strUS2)
            strNM = strUS2(i)
            Exit For
        Next
     
        '** Assign password and parameters:'
        If strNM <> "" Then
            TNP = "changeme" & Mid(objFSO.GetTempName,4,4)
            objUser.SetPassword TNP
            If Err <> 0 Then
                EROR = 1
            End If
            objUser.Put "pwdLastSet", 0
            objUser.IsAccountLocked = False
            objUser.SetInfo
        End If
     
        '** If no error, show new temporary password:'
        If EROR <> 1 Then
            MsgBox "New temporary password for " & UCase(USR) & " (" & strNM & "):" & _
            vbCrLf & vbCrLf & TNP & vbCrLf, 64, "New Password, configured by " & strNM2
        End If
 
    End If
 
    '** End if object not found:'
    If ABS = 1 Then
        MsgBox UCase(USR) & " was not found. Please try again.", _
        48, "Unknown Username"
    End If
 
    '** If no permission, give message:'
    If EROR = 1 Then
        MsgBox "You can not change password for this user.", _
        48, "Permission Denied"
    End If
 
End Sub 
 
Sub ImportFromExcel
    on error resume next
    boolEndofFile = False
    Dim oDLG
    Set oDLG = CreateObject("MSComDlg.CommonDialog")
    if err.number > 0 then
        err.clear
        oDLG = window.prompt("Please enter the path and file name to open.", "D:\your-spreadsheet.xls")
        if oDLG <> "" then
            globalstrQueryBuilder = ""
            Set objExcel = CreateObject("Excel.Application")
            Set objWorkbook = objExcel.Workbooks.Open(oDLG)
            intRow = 2
            Do Until boolEndofFile
                'According to ticket Q__23804616, these are the fields that are in the spreadsheet;
                'Emp ID,Seat No,Email ID,Full Name, NT Login,Machine Name
                strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                    boolEndofFile = True
                else
                    if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                    if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                    if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                    if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                    if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                    if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                end if
                intRow = intRow + 1
            Loop
            objExcel.Quit
            globalstrQueryBuilder = strValue
	    globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	    globalstrSearchBtnPush = "FileOpen"
	    Submit_Form "FileOpen"
        End If
    else
        With oDLG
            .DialogTitle = "Open"
            .Filter = "Excel Workbook|*.xls"
            .MaxFileSize = 255
            .Flags = .Flags Or &H1000	'FileMustExist (OFN_FILEMUSTEXIST)
            .ShowOpen
            If .FileName <> "" Then
                globalstrQueryBuilder = ""
                Set objExcel = CreateObject("Excel.Application")
                Set objWorkbook = objExcel.Workbooks.Open(.FileName)
                intRow = 2
                Do Until boolEndofFile
                    strCell1 = objExcel.Cells(intRow, 1).Value 'Must be the "Employee ID" field
                    strCell2 = objExcel.Cells(intRow, 2).Value 'Must be the "Seat No" field
                    strCell3 = objExcel.Cells(intRow, 3).Value 'Must be the "Email Address" field
                    strCell4 = objExcel.Cells(intRow, 4).Value 'Must be the "Full Name" field
                    strCell5 = objExcel.Cells(intRow, 5).Value 'Must be the "NT Login" field
                    strCell6 = objExcel.Cells(intRow, 6).Value 'Must be the "Machine Name" field
                    if strCell1 & strCell2 & strCell3 & strCell4 & strCell5 & strCell6 = "" then
                        boolEndofFile = True
                    else
                        if NOT IsEmpty(strCell1) then strValue = strValue & "(description=*" & strCell1 & "*)"    'Employee ID
                        if NOT IsEmpty(strCell2) then strValue = strValue & "(description=*" & strCell2 & "*)"    'Seat No
                        if NOT IsEmpty(strCell3) then strValue = strValue & "(mail=*" & strCell3 & "*)"           'Email Address 
                        if NOT IsEmpty(strCell4) then strValue = strValue & "(cn=*" & strCell4 & "*)"             'Full Name
                        if NOT IsEmpty(strCell5) then strValue = strValue & "(samAccountName=*" & strCell5 & "*)" 'NT Login
                        if NOT IsEmpty(strCell6) then strValue = strValue & "(description=*" & strCell6 & "*)"    'Machine Name
                    end if
                    intRow = intRow + 1
                Loop
                objExcel.Quit
                globalstrQueryBuilder = strValue
	        globalStrSearchField = "(|" & globalstrQueryBuilder & ")"
	        globalstrSearchBtnPush = "FileOpen"
	        Submit_Form "FileOpen"
            End If
        End With
    end if
    Set oDLG = Nothing
End Sub
 
Sub About_OnClick
    'Enter names as contibuters increase.
    msgbox vbCRLF & "User and Computer Account Control" & vbCRLF & vbCRLF & "Written for Sharatha and contributed by;" & vbCRLF & vbCRLF & vbtab & _
    """rejoinder""" & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab & _
    "             " & vbCRLF & vbtab
End Sub
 
Sub RunHTA(NameOfHTA)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run NameOfHTA
End Sub
 
Sub allowpings
    if chk_allowpings.Checked then
        boolAllowPing = True
    else
        boolAllowPing = False
    end if
End Sub
 
Sub LookupLastLogin
    if chk_LookupLastLogin.Checked then
        boolLookupLastLogin = True
    else
        boolLookupLastLogin = False
    end if
End Sub
 
Sub TableReports
    if chk_TableReports.Checked then
        boolTableReports = True
    else
        boolTableReports = False
    end if
End Sub
 
Sub GetMailboxDetails
    on error resume next
    strExchangeServerQuery = "winmgmts://" & strEmailServer & "/root/cimv2/applications/exchange"
    set serverList = GetObject(strExchangeServerQuery).InstancesOf("ExchangeServerState")
    For each ExchangeServer in serverList
        strExchangeQuery = "winmgmts://" & ExchangeServer.Name & "/root/MicrosoftExchangeV2"
        strExchangeQuery = "winmgmts://" & strEmailServer & "/root/MicrosoftExchangeV2"
        Set objMailboxes = GetObject(strExchangeQuery).InstancesOf("Exchange_Mailbox")
        For each mailbox in objMailboxes
            MailboxList.AddNew
            MailboxList("legacyExchangeDN") = mailbox.LegacyDN
            MailboxList("mailboxsize") = Round(mailbox.Size / 1024)
            MailboxList.Update
        Next
    Next
    MailboxList.MoveFirst
End Sub
 
Sub MailboxSizeCompare
    oDLG = window.prompt("Enter the mailbox size limit in MB.", "1000")
    if IsNumeric(oDLG) then
        Submit_Form("MailboxSize:" & oDLG)
    end if
End Sub
 
Sub DoCal(elTarget)
    sRtn = showModalDialog("Calendar.htm","","center=yes;dialogWidth=160pt;dialogHeight=180pt")
    Execute(elTarget & ".value = sRtn")
    Detect_Search_Field(elTarget)
End Sub
 
Function GetOUMembers(OU)
    strValue = ""
    on error resume next
    GroupMembershipDB.Filter = "MemberDistinguishedName LIKE '*OU=" & OU & "*'"
    GroupMembershipDB.Sort   = "SAMAccountName"
    GroupMembershipDB.MoveFirst
    Do While Not GroupMembershipDB.EOF
        strValue = strValue & "(DistinguishedName=" & GroupMembershipDB.Fields.Item("MemberDistinguishedName").Value & ")"
        GroupMembershipDB.MoveNext
    Loop
    if err.number > 0 then
        GetOUMembers = "INVALID"
    else
        GetOUMembers = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForOSQuery(OS)
    strValue = ""
    strSearchField = "(operatingsystem=*" & OS & "*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForOSQuery = "INVALID"
    else
        GetComputersForOSQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersForDateCreatedQuery(CreatedDate)
    strValue = ""
    strWhenCreated = Year(CreatedDate) & Right("0" & Month(CreatedDate), 2) & Right("0" & Day(CreatedDate), 2)
    strSearchField = "(whenCreated>=" & strWhenCreated & "000000.0Z)(whenCreated<=" & strWhenCreated & "235959.0Z)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    boolFoundRecords = False
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,operatingsystem"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersForDateCreatedQuery = "INVALID"
    else
        GetComputersForDateCreatedQuery = "(|" & strValue & ")"
    End if
End Function
 
Function GetComputersBasedOnOU(OU)
    strValue = ""
    
    strSearchField = "(distinguishedName=*)"
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
            
    boolFoundRecords = False
            
    for each strDomain in arrDomainNames
        ' Search entire Active Directory domain.
        strBase = "<LDAP://" & strDomain & ">"
                  
        strFilter = "(&(objectCategory=computer)" & strSearchField & ")"
 
        ' Comma delimited list of attribute values to retrieve.
        strAttributes = "cn,distinguishedName"
        ' Construct the LDAP syntax query.
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
 
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 1000
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
                  
        ' Run the query.
        Set adoRecordset = adoCommand.Execute
        ' Enumerate the resulting recordset.
        strDetails = ""
        If Not adoRecordset.EOF Then
            boolFoundRecords = True
            Do Until adoRecordset.EOF
                if InStr(adoRecordset.Fields("distinguishedName").Value,OU) > 0 then
                    strValue = strValue & "(info=*" & adoRecordset.Fields("cn").Value & "*)"
                End if
                adoRecordset.MoveNext
            Loop
        End if
    next
    if NOT boolFoundRecords then
        GetComputersBasedOnOU = "INVALID"
    else
        GetComputersBasedOnOU = "(|" & strValue & ")"
    End if
End Function
 
Sub txt_filtersecuritygroup_onKeyUP
    on error resume next
    if txt_filtersecuritygroup.Value <> "" then
        Detect_Search_Field "txt_filtersecuritygroup"
        Set objlst_groupnames = document.getElementById( "lst_groupnames" )
        objlst_groupnames.ListItems.Clear
        GroupMembershipDB.Filter = "samaccountname LIKE '*" & txt_filtersecuritygroup.Value & "*'"
        GroupMembershipDB.Sort = "SAMAccountName"
        GroupMembershipDB.MoveFirst
        strLastGroupDN = ""
        Do Until GroupMembershipDB.EOF
            strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
            strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
            strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
            intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
            if strLastGroupDN <> strdistinguishedName then
                Select Case strGroupType
                    Case "[GSG]", "[LSG]", "[USG]", "[Unknown]"
                        Set objListItem  = objlst_groupnames.ListItems.Add
                        objListItem.Text = strNTName
                        objListItem.ListSubItems.Add.Text = intNumberOfMembers
                        objListItem.ListSubItems.Add.Text = strGroupType
                        objListItem.ListSubItems.Add.Text = strdistinguishedName
                        objListItem.ListSubItems.Add.Text = strPrimary
                End Select
                strLastGroupDN = strdistinguishedName
            End if
            GroupMembershipDB.MoveNext
        Loop
        span_GroupMembership.InnerHTML = "(" & lst_groupnames.ListItems.Count & ")"
    end if
End Sub
 
Sub txt_filterdgmembership_onKeyUP
    on error resume next
    if txt_filterdgmembership.Value <> "" then
        Detect_Search_Field "txt_filterdgmembership"
        Set objlst_dgnames = document.getElementById( "lst_dgnames" )
        objlst_dgnames.ListItems.Clear
        GroupMembershipDB.Filter = "samaccountname LIKE '*" & txt_filterdgmembership.Value & "*'"
        GroupMembershipDB.Sort = "SAMAccountName"
        GroupMembershipDB.MoveFirst
        strLastGroupDN = ""
        Do Until GroupMembershipDB.EOF
            strGroupType         = GroupMembershipDB.Fields.Item("samaccounttype").Value
            strNTName            = GroupMembershipDB.Fields.Item("samaccountname").Value
            strPrimary           = GroupMembershipDB.Fields.Item("PrimaryGroupToken").Value
            strdistinguishedName = GroupMembershipDB.Fields.Item("distinguishedName").Value
            intNumberOfMembers   = dicGroupNumbers.Item(strdistinguishedName)
    
            if strLastGroupDN <> strdistinguishedName then
                Select Case strGroupType
                    Case "[GDG]", "[LDG]", "[UDG]"
                        Set objListItem  = objlst_dgnames.ListItems.Add
                        objListItem.Text = strNTName
                        objListItem.ListSubItems.Add.Text = intNumberOfMembers
                        objListItem.ListSubItems.Add.Text = strGroupType
                        objListItem.ListSubItems.Add.Text = strdistinguishedName
                        objListItem.ListSubItems.Add.Text = strPrimary
                End Select
                strLastGroupDN = strdistinguishedName
            End if
            GroupMembershipDB.MoveNext
        Loop
        span_groupmembership.InnerHTML = "(" & lst_dgnames.ListItems.Count & ")"
    end if
End Sub
 
Sub txt_filtermanagerlist_onKeyUP
    if txt_filtermanagerlist.Value <> "" then
        Detect_Search_Field "txt_filtermanagerlist"
        For Each objOption in lst_managerlist.Options
            objOption.RemoveNode
        Next
        intManagers = 0
        for each Manager in dicManagerList
            if InStr(UCase(Manager),UCase(txt_filtermanagerlist.Value)) then
                set newOption = document.createElement("OPTION")
                newOption.Text = mid(Manager,4,instr(Manager,",")-4) & " (" & dicManagerList.Item(Manager) & ")"
                newOption.Value = Manager
                lst_managerlist.Add newOption
                intManagers = intManagers + 1
            end if
        next
        span_managerlist.InnerHTML = "(" & intManagers & ")"
    end if
End Sub
 
Function GetMailboxStore(MailboxStore)
    if MailboxStore <> "" OR NOT IsNull(MailboxStore) then
        arrMailboxStoreString = Split(MailboxStore,"CN=")
        GetMailboxStore = replace(arrMailboxStoreString(2),",","")
    else
        GetMailboxStore = ""
    End if
End Function
 
Sub FillDomainComputers
    On Error Resume Next
    Const ADS_SCOPE_SUBTREE = 2
    Set objlst_domaincomputers = document.getElementById( "lst_domaincomputers" )
    objlst_domaincomputers.ListItems.Clear
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    adoCommand.Properties("Page Size") = 1000
    adoCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    adoCommand.CommandText = "SELECT ADsPath FROM 'LDAP://" & strDNSDomain & "' WHERE objectCategory='organizationalUnit'"  
    Set objRecordSet = adoCommand.Execute
    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
        Set objOU = GetObject(objRecordSet.Fields("ADsPath").Value)
        objOU.Filter = Array("Computer")
        For Each objItem in objOU
            strCN = objItem.CN
            strDN = objItem.distinguishedName
            DomainComputersDB.AddNew
            DomainComputersDB("CN") = strCN
            DomainComputersDB("DistinguishedName") = strDN
            DomainComputersDB.Update
            Set objListItem  = objlst_domaincomputers.ListItems.Add
            objListItem.Text = strCN
            objListItem.ListSubItems.Add.Text = strDN
        Next
        objRecordSet.MoveNext
    Loop
    span_domaincomputers.InnerHTML = "(" & lst_domaincomputers.ListItems.Count & ")"
End Sub
 
Sub lst_domaincomputers_onDblClick
    strComputer = lst_domaincomputers.SelectedItem.Text
    txt_notes.Value = strComputer
    Detect_Search_Field "txt_notes"
    Submit_Form "Main"
End Sub
 
Sub txt_filterdomaincomputers_onKeyUP
    on error resume next
    if txt_filterdomaincomputers.Value <> "" then
        Detect_Search_Field "txt_filterdomaincomputers"
        Set objlst_domaincomputers = document.getElementById( "lst_domaincomputers" )
        objlst_domaincomputers.ListItems.Clear
        intDomainComputers = 0
        DomainComputersDB.Filter = "CN LIKE '*" & txt_filterdomaincomputers.Value & "*'"
        DomainComputersDB.Sort = "CN"
        DomainComputersDB.MoveFirst
        Do Until DomainComputersDB.EOF
            strCN = DomainComputersDB.Fields.Item("CN").Value
            strDN = DomainComputersDB.Fields.Item("DistinguishedName").Value
            Set objListItem  = objlst_domaincomputers.ListItems.Add
            objListItem.Text = strCN
            objListItem.ListSubItems.Add.Text = strDN
            DomainComputersDB.MoveNext
        Loop
        span_domaincomputers.InnerHTML = "(" & lst_domaincomputers.ListItems.Count & ")"
    else
        populatedomaincomputers
    end if
End Sub
 
Sub populatedomaincomputers
    on error resume next
    Set objlst_domaincomputers = document.getElementById( "lst_domaincomputers" )
    objlst_domaincomputers.ListItems.Clear
    intDomainComputers = 0
    DomainComputersDB.Filter = ""
    DomainComputersDB.Sort = "CN"
    DomainComputersDB.MoveFirst
    Do Until DomainComputersDB.EOF
        strCN = DomainComputersDB.Fields.Item("CN").Value
        strDN = DomainComputersDB.Fields.Item("DistinguishedName").Value
        Set objListItem  = objlst_domaincomputers.ListItems.Add
        objListItem.Text = strCN
        objListItem.ListSubItems.Add.Text = strDN
        DomainComputersDB.MoveNext
    Loop
    span_domaincomputers.InnerHTML = "(" & lst_domaincomputers.ListItems.Count & ")"
End Sub
 
Sub ResetComputerPassword
    if txt_notes.value <> "" then
        DomainComputersDB.Filter = "CN='" & txt_notes.value & "'"
        DomainComputersDB.MoveFirst
        strLDAP = "LDAP://" & DomainComputersDB.Fields.Item("DistinguishedName").Value
        set objComputer = GetObject(strLDAP)
        objComputer.SetPassword txt_notes.value & "$"
    else
        msgbox "Please enter a valid computer name."
    End if
End Sub
 
</script>
 
<script language ='javascript' for ='lst_groupnames' event ='ColumnClick(ColumnHeader)'> 
 
if(ColumnHeader.SubItemIndex == lst_groupnames.SortKey)
{
if(lst_groupnames.SortOrder == 0) lst_groupnames.SortOrder = 1
else lst_groupnames.SortOrder = 0
} 
else 
{
lst_groupnames.SortKey = ColumnHeader.SubItemIndex
if(lst_groupnames.SortOrder == 0) lst_groupnames.SortOrder = 1
else lst_groupnames.SortOrder == 0
}
</script>
 
<script language ='javascript' for ='lst_groupnames' event ='DblClick'> 
var theValue = ""
theValue = SelectedItem.Text + SelectedItem.Key
for(i = 1; i <= SelectedItem.ListSubItems.Count; i ++) theValue = theValue + "\n" + SelectedItem.ListSubItems(i).Text
Submit_Form('Group')
</script>
 
<script language ='javascript' for ='lst_dgnames' event ='ColumnClick(ColumnHeader)'> 
 
if(ColumnHeader.SubItemIndex == lst_dgnames.SortKey)
{
if(lst_dgnames.SortOrder == 0) lst_dgnames.SortOrder = 1
else lst_dgnames.SortOrder = 0
} 
else 
{
lst_dgnames.SortKey = ColumnHeader.SubItemIndex
if(lst_dgnames.SortOrder == 0) lst_dgnames.SortOrder = 1
else lst_dgnames.SortOrder == 0
}
</script>
 
<script language ='javascript' for ='lst_dgnames' event ='DblClick'> 
var theValue = ""
theValue = SelectedItem.Text + SelectedItem.Key
for(i = 1; i <= SelectedItem.ListSubItems.Count; i ++) theValue = theValue + "\n" + SelectedItem.ListSubItems(i).Text
Submit_Form('DistributionGroup')
</script>
 
<script language ='javascript' for ='lst_domaincomputers' event ='ColumnClick(ColumnHeader)'> 
 
if(ColumnHeader.SubItemIndex == lst_domaincomputers.SortKey)
{
if(lst_domaincomputers.SortOrder == 0) lst_domaincomputers.SortOrder = 1
else lst_domaincomputers.SortOrder = 0
} 
else 
{
lst_domaincomputers.SortKey = ColumnHeader.SubItemIndex
if(lst_domaincomputerss.SortOrder == 0) lst_domaincomputers.SortOrder = 1
else lst_domaincomputers.SortOrder == 0
}
</script>
 
<script language ='javascript' for ='lst_domaincomputers' event ='DblClick'> 
var theValue = ""
theValue = SelectedItem.Text + SelectedItem.Key
for(i = 1; i <= SelectedItem.ListSubItems.Count; i ++) theValue = theValue + "\n" + SelectedItem.ListSubItems(i).Text
lst_domaincomputers_onDblClick()
</script>
 
 
<STYLE TYPE="text/css">
<!--
body		{background-color: menu;color: menutext;}
td		{font-family: MS Sans Serif;font-size: 8pt;}
input		{font-family: MS Sans Serif;font-size: 8pt;}
button		{font-family: MS Sans Serif;font-size: 8pt;}
option		{font-family: MS Sans Serif;font-size: 8pt;}
select		{font-family: MS Sans Serif;font-size: 8pt;}
.submenu	{position:absolute;top=35;
		background-color:Menu;
		border="1px outset";}
.MenuIn		{border:"1px inset";cursor:default;}
.Menuover	{border:"1px outset";cursor:default;}
.Menuout	{}
.Submenuover	{background-color:highlight;color:highlighttext;cursor:default;}
.Submenuout	{background-color:Menu;color:MenuText;cursor:default;}
.HideFromGUI	{display:none;}
 
-->
</STYLE>
<body>
<!-- Main menu -->
<TABLE id=MenuTable height=25><TR>
	<TD	onclick='ShowSubMenu Me,MyFileMenu'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> Query </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,MyEditMenu'
		onmouseover='MenuOver Me,MyEditMenu'
		onmouseout='MenuOut Me'> Reports </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,QueryBuilderMenu'
		onmouseover='MenuOver Me,QueryBuilderMenu'
		onmouseout='MenuOut Me'> Query&nbsp;Builder </TD>
	<TD	>|</TD>
	<TD	onclick='ShowSubMenu Me,ToolsMenu'
		onmouseover='MenuOver Me,ToolsMenu'
		onmouseout='MenuOut Me'> Tools </TD>
	<TD	>|</TD>
	<TD	> Checkbox&nbsp;Profile&nbsp;<select id="lst_chkprofiles" name="lst_chkprofiles">
 
	</select>
	</TD>
<!-- Main menu, Checkbox profile tools -->
	<TD	onclick='AddToCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [+]Add</TD>
	<TD	onclick='DeleteFromCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [-]Delete</TD>
	<TD	onclick='ModifyCurrentCheckboxProfile'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me' NOWRAP> [!]Modify</TD>
	<TD	>|</TD>
	<TD	onclick='About_OnClick'
		onmouseover='MenuOver Me,MyFileMenu'
		onmouseout='MenuOut Me'> About</TD>
	<TD	>|</TD>
	<TD onclick="HideMenu" width="100%" border="2"></TD>
	</TR></TABLE>
<!-- Drop down for QUery -->
<TABLE ID=MyFileMenu class=submenu style="left=10;display:none;">
        <TR><TD	onclick="HideMenu:open"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Open</TD></TR>
        <TR><TD onclick="HideMenu:importfromexcel"
                onmouseover='Submenuover Me'
                onmouseout='Submenuout Me'> Import from Excel</TD></TR>
	<TR><TD	onclick="HideMenu:save"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save</TD></TR>
	<TR><TD	onclick="HideMenu:saveAs"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save As</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:window.close"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Quit</TD></TR>
</TABLE>
<!-- Drop down for Reports -->
<TABLE ID=MyEditMenu class=submenu style="left=50;display:none;">
        <TR><TD	onclick="HideMenu:Email_This_Record"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email This Record</TD></TR>
	<TR><TD	onclick="HideMenu:Email_All_Records"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email All Records</TD></TR>
	<TR><TD	onclick="HideMenu:Email_As_Attachment"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Email as Attachment</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:RunScript"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Save to</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:ClickTheSpecialReportButton"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> All Disabled Users</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified Today</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportDisabledUsersSomeDay"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Disabled Users Last Modified...</TD></TR>
	<TR><TD	onclick="HideMenu:SpecialReportNewUsersToday"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> New Users Created Today</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:7')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 week</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:30')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 1 month</TD></TR>
	<TR><TD	onclick="HideMenu:Submit_Form('Logon:60')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Not logged in for 2 months</TD></TR>
	<TR><TD><HR></TD></TR>
	<TR><TD	onclick="HideMenu:MailboxSizeCompare"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Users with mailbox size over...</TD></TR>
</TABLE>
<!-- Drop down for Query Builder -->
<TABLE ID=QueryBuilderMenu class=submenu style="left=97;display:none;">
        <TR><TD	onclick="HideMenu:AddToQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Add recent query to Query Builder</TD></TR>
        <TR><TD	onclick="HideMenu:QueryBuilderRecorder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Query Builder Recorder<input type="checkbox" id="chk_qbrecorder" name="chk_qbrecorder"></TD></TR>
	<TR><TD	onclick="HideMenu:ViewQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> View Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:RunQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Run Query Builder</TD></TR>
	<TR><TD	onclick="HideMenu:ClearQueryBuilder"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Clear Query Builder</TD></TR>
</TABLE>
<!-- Drop down for Tools -->
<TABLE ID=ToolsMenu class=submenu style="left=170;display:none;">
        <TR><TD	onclick="HideMenu:allowpings"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Allow Pings<input type="checkbox" id="chk_allowpings" name="chk_allowpings"></TD></TR>
        <TR><TD	onclick="HideMenu:LookupLastLogin"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Look up last login<input type="checkbox" id="chk_LookupLastLogin" name="chk_LookupLastLogin"></TD></TR>
        <TR><TD	onclick="HideMenu:tablereports"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Invert emails to table format<input type="checkbox" id="chk_tablereports" name="chk_tablereports"></TD></TR>
	<TR><TD><HR></TD></TR>
        <TR><TD	onclick="HideMenu:RunHTA('HTA1.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 1</TD></TR>
	<TR><TD	onclick="HideMenu:RunHTA('HTA2.HTA')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Launch HTA 2</TD></TR>
	<TR><TD	onclick="HideMenu:RunHTA('Q_23768297.hta')"
		onmouseover='Submenuover Me'
		onmouseout='Submenuout Me'> Add Users to Groups</TD></TR>
</TABLE>
<hr>
 <table width="100%" border="0" onclick="HideMenu">
            <tr>
                  <td align="left" colspan="2" valign="top">
                        <table border="0" padding="1">
                              <tr>
                                    <td>
                                         <fieldset>
                                         <LEGEND>Email Settings</LEGEND>
                                         <table border="0">
                                         <tr><td>To:</td><td><button onclick="ShowDialogTo">Resolve</button></td><td><input type="text" id="txt_EmailTo" name="txt_EmailTo" size="50"><input type="hidden" id="txt_EmailToHidden" name="txt_EmailToHidden" size="50"><br></td></td><td rowspan="4" valign="top">Email&nbsp;Body:</td><td rowspan="3" valign="top"><textarea id="txt_EmailBody" name="txt_EmailBody" rows=5 cols=40></TEXTAREA></td></tr>
                                         <tr><td>CC:</td><td><button onclick="ShowDialogCC">Resolve</button></td><td><input type="text" id="txt_EmailCC" name="txt_EmailCC" size="50"><input type="hidden" id="txt_EmailCCHidden" name="txt_EmailCCHidden" size="50"><br></td></tr>
                                         <tr><td>Email Subject:</td><td></td><td><select id="txt_EmailSubject" name="txt_EmailSubject"></select></td></tr>
                                         </table>
                                         </fieldset>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
            <tr>
                  <td align="left" valign="top" width="38%">
                        <table border="0">
                              <tr>
                                    <td>
                                          &nbsp;
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_selectall" name="chk_selectall" checked=True onclick="vbs:SelectAllCheck">Select/Deselect All
                                    </td>
                              </tr>
                              <tr id=tr_seatno>
                                    <td>
                                          Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_seatno" name="chk_seatno" checked=True><input type="text" size="40" id="txt_seatno" name="txt_seatno" onkeypress="vbs:Detect_Search_Field('txt_seatno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacementseatno>
                                    <td>
                                          Replacement Seat No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacementseatno" name="chk_replacementseatno" checked=True><input type="text" size="40" id="txt_replacementseatno" name="txt_replacementseatno">
                                    </td>
                              </tr>
                              <tr id=tr_building>
                                    <td>
                                          Building:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_building" name="chk_building" checked=True><input type="text" size="40" id="txt_building" name="txt_building" onkeypress="vbs:Detect_Search_Field('txt_building')">
                                    </td>
                              </tr>
                              <tr id=tr_extensionno>
                                    <td>
                                          Extension No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_extensionno" name="chk_extensionno" checked=True><input type="text" size="40" id="txt_extensionno" name="txt_extensionno" onkeypress="vbs:Detect_Search_Field('txt_extensionno')">
                                    </td>
                              </tr>
                              <tr id=tr_empid>
                                    <td>
                                          Emp ID:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_empid" name="chk_empid" checked=True><input type="text" size="10" id="txt_empid" name="txt_empid" onkeypress="vbs:Detect_Search_Field('txt_empid')">
                                    </td>
                              </tr>
                              <tr id=tr_department>
                                    <td>
                                          Department:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_department" name="chk_department" checked=True><input type="text" size="50" id="txt_department" name="txt_department" onkeypress="vbs:Detect_Search_Field('txt_department')">
                                    </td>
                              </tr>
                              <tr id=tr_designation>
                                    <td>
                                          Designation:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_designation" name="chk_designation" checked=True><input type="text" size="50" id="txt_designation" name="txt_designation" onkeypress="vbs:Detect_Search_Field('txt_designation')">
                                    </td>
                              </tr>
                              <tr id=tr_name>
                                    <td>
                                          User Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_name" name="chk_name" checked=True><input type="text" size="40" id="txt_name" name="txt_name" onkeypress="vbs:Detect_Search_Field('txt_name')">
<span id="span_userorcontact">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_loginname>
                                    <td>
                                          Login Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_loginname" name="chk_loginname" checked=True><input type="text" size="40" id="txt_loginname" name="txt_loginname" onkeypress="vbs:Detect_Search_Field('txt_loginname')"> 
<span id="span_enabled">
 
</span>
                                    </td>
                              </tr>
                              <tr id=tr_email>
                                    <td>
                                          Email Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_email" name="chk_email" checked=True><input type="text" size="50" id="txt_email" name="txt_email" onkeypress="vbs:Detect_Search_Field('txt_email')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxsize>
                                    <td>
                                          Mailbox Size (MB):
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxsize" name="chk_mailboxsize" checked=True><input type="text" size="20" id="txt_mailboxsize" name="txt_mailboxsize" onkeypress="vbs:Detect_Search_Field('txt_mailboxsize')">
                                    </td>
                              </tr>
                              <tr id=tr_mailboxstore>
                                    <td>
                                          Mailbox Store:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mailboxstore" name="chk_mailboxstore" checked=True><input type="text" size="50" id="txt_mailboxstore" name="txt_mailboxstore" onkeypress="vbs:Detect_Search_Field('txt_mailboxstore')">
                                    </td>
                              </tr>
                              <tr id=tr_mobileno>
                                    <td>
                                          Mobile Number:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_mobileno" name="chk_mobileno" checked=True><input type="text" size="20" id="txt_mobileno" name="txt_mobileno" onkeypress="vbs:Detect_Search_Field('txt_mobileno')">
                                    </td>
                              </tr>
                              <tr id=tr_company>
                                    <td>
                                          Company:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_company" name="chk_company" checked=True><input type="text" size="20" id="txt_company" name="txt_company" onkeypress="vbs:Detect_Search_Field('txt_company')">
                                    </td>
                              </tr>
                              <tr id=tr_address>
                                    <td>
                                          Address:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_address" name="chk_address" checked=True><input type="text" size="20" id="txt_address" name="txt_address" onkeypress="vbs:Detect_Search_Field('txt_address')">
                                    </td>
                              </tr>
                              <tr id=tr_city>
                                    <td>
                                          City:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_city" name="chk_city" checked=True><input type="text" size="20" id="txt_city" name="txt_city" onkeypress="vbs:Detect_Search_Field('txt_city')">
                                    </td>
                              </tr>
                              <tr id=tr_state>
                                    <td>
                                          State:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_state" name="chk_state" checked=True><input type="text" size="20" id="txt_state" name="txt_state" onkeypress="vbs:Detect_Search_Field('txt_state')">
                                    </td>
                              </tr>
                              <tr id=tr_zipcode>
                                    <td>
                                          Zip Code:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_zipcode" name="chk_zipcode" checked=True><input type="text" size="20" id="txt_zipcode" name="txt_zipcode" onkeypress="vbs:Detect_Search_Field('txt_zipcode')">
                                    </td>
                              </tr>
                              <tr id=tr_country>
                                    <td>
                                          Country:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_country" name="chk_country" checked=True><input type="text" size="20" id="txt_country" name="txt_country" onkeypress="vbs:Detect_Search_Field('txt_country')">
                                          &nbsp&nbspMust search by 2 letter country code
                                    </td>
                              </tr>
                              <tr id=tr_homephone>
                                    <td>
                                          Home Phone:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_homephone" name="chk_homephone" checked=True><input type="text" size="20" id="txt_homephone" name="txt_homephone" onkeypress="vbs:Detect_Search_Field('txt_homephone')">
                                    </td>
                              </tr>
                              <tr id=tr_manager>
                                    <td>
                                          Manager:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_manager" name="chk_manager" checked=True><input type="hidden" size="20" id="txt_manager" name="txt_manager"><input type="text" size="20" id="txt_managerseen" name="txt_managerseen" onkeypress="vbs:Detect_Search_Field('txt_managerseen')">
                                    </td>
                              </tr>
                              <tr id=tr_whencreated>
                                    <td>
                                          Date Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_whencreated" name="chk_whencreated" checked=True><input type="text" size="40" id="txt_whencreated" name="txt_whencreated" onkeypress="vbs:Detect_Search_Field('txt_whencreated')"><input type=button value="Pick" onclick="DoCal('txt_whencreated')">
                                    </td>
                              </tr>
                              <tr id=tr_oupathuser>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathuser" name="chk_oupathuser" checked=True><input type="text" size="50" id="txt_oupathuser" name="txt_oupathuser" onkeypress="vbs:Detect_Search_Field('txt_oupathuser')">
                                    </td>
                              </tr>
                              <tr id=tr_lastlogintimestamp>
                                    <td>
                                          Last Login:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_lastlogintimestamp" name="chk_lastlogintimestamp" checked=True><input type="text" size="50" id="txt_lastlogintimestamp" name="txt_lastlogintimestamp" onkeypress="vbs:Detect_Search_Field('txt_lastlogintimestamp')">
                                    </td>
                              </tr>
                              <tr>
                                    <td colspan="2" align="center">
                                          <br>Showing record&nbsp
                                          <span id="span_currentrecord">
                                          0
                                          </span>
                                          &nbsp;of&nbsp;
                                          <span id="span_totalrecords">
                                          0
                                          </span>
                                          <br><br>
                                          <input type="button" value='||< First' name='btnFirstEvent'  onClick='vbs:First_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='<< Previous' name='btnPreviousEvent'  onClick='vbs:Previous_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Next >>' name='btnNextEvent'  onClick='vbs:Next_Event'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Last >||' name='btnLastEvent'  onClick='vbs:Last_Event'><br><br>
                                          <input type="button" value='Email this record' name='btnEmailThisRecord'  onClick='vbs:Email_This_Record'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email all records' name='btnEmailAllRecords'  onClick='vbs:Email_All_Records'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                          <input type="button" value='Email as attachment' name='btnEmailAsAttachment'  onClick='vbs:Email_As_Attachment'><br><br>
                                          <input type="button" value='Clear Form' name='btnClearForm'  onClick='vbs:Clear_Form("resetGroupLists")'>
                                          <input type="submit" value="Submit" name="btn_submit" onClick="vbs:Submit_Form('Main')">
                                          <input id="runbutton"  class="button" type="button" value="Save to" name="run_button" onClick="Runscript">
                                          <input id="runbutton"  class="button" type="button" value="Change PWD" name="bt1go">
                                          <input id="runbutton"  class="button" type="button" value="Enable/Disable User" name="bt2go">
                                    </td>
                              </tr>
                        </table>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset>
                  <LEGEND>Computer Information</LEGEND>
                  <table>
                              <tr id=tr_notes>
                                    <td valign="top">
                                         Machine Name:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_notes" name="chk_notes" checked=True><input type="text" size="40" id="txt_notes" name="txt_notes" onkeypress="vbs:Detect_Search_Field('txt_notes')"><input type="button" value='Reset' name='btnResetComputerPassword'  onClick='vbs:ResetComputerPassword'>
<br>IP: <span id="span_computerip"> </span><br>
Status: <span id="span_computeronline"> </span>
                                    </td>
                              </tr>
                              <tr id=tr_computerserialno>
                                    <td>
                                         Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerserialno" name="chk_computerserialno" checked=True><input type="text" size="40" id="txt_computerserialno" name="txt_computerserialno" onkeypress="vbs:Detect_Search_Field('txt_computerserialno')">
                                    </td>
                              </tr>
                              <tr id=tr_replacedmachine>
                                    <td>
                                         Replaced Machine:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedmachine" name="chk_replacedmachine" checked=True><input type="text" size="40" id="txt_replacedmachine" name="txt_replacedmachine">
                                    </td>
                              </tr>
                              <tr id=tr_replacedcomputerserialno>
                                    <td>
                                         Replaced Serial No:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_replacedcomputerserialno" name="chk_replacedcomputerserialno" checked=True><input type="text" size="40" id="txt_replacedcomputerserialno" name="txt_replacedcomputerserialno">
                                    </td>
                              </tr>
                              <tr id=tr_oupathcomputer>
                                    <td>
                                          OU Path:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_oupathcomputer" name="chk_oupathcomputer" checked=True><input type="text" size="40" id="txt_oupathcomputer" name="txt_oupathcomputer" onkeypress="vbs:Detect_Search_Field('txt_oupathcomputer')">
                                    </td>
                              </tr>
                              <tr id=tr_computeros>
                                    <td>
                                          Computer OS:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computeros" name="chk_computeros" checked=True><input type="text" size="19" id="txt_computeros" name="txt_computeros" onkeypress="vbs:Detect_Search_Field('txt_computeros')">
                                          <input type="text" size="18" id="txt_computerservicepack" name="txt_computerservicepack" onkeypress="vbs:Detect_Search_Field('txt_computerservicepack')">
                                    </td>
                              </tr>
                              <tr id=tr_computerdescription>
                                    <td>
                                         Description:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computerdescription" name="chk_computerdescription" checked=True><input type="text" size="40" id="txt_computerdescription" name="txt_computerdescription" onkeypress="vbs:Detect_Search_Field('txt_computerdescription')">
                                    </td>
                              </tr>
                              <tr id=tr_computercreated>
                                    <td>
                                          Created:
                                    </td>
                                    <td>
                                          <input type="checkbox" id="chk_computercreated" name="chk_computercreated" checked=True><input type="text" size="40" id="txt_computercreated" name="txt_computercreated" onkeypress="vbs:Detect_Search_Field('txt_computercreated')"><input type=button value="Pick" onclick="DoCal('txt_computercreated')">
                                    </td>
                              </tr>
                  </table>
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_domaincomputers>
                  <LEGEND><!--<input type="checkbox" id="chk_domaincomputers" name="chk_domaincomputers" checked=True>-->Domain Computers <span id="span_domaincomputers"></span></LEGEND>
                  &nbsp;<OBJECT id="lst_domaincomputers" name="lst_domaincomputers" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filterdomaincomputers" name="txt_filterdomaincomputers">
                  </fieldset>
                  <br><br>
                  </td>
                  <td align="left" valign="top" width="31%">
                  <fieldset id=tr_groupmembership>
                  <LEGEND><input type="checkbox" id="chk_groupmembership" name="chk_groupmembership" checked=True>Group Membership <span id="span_groupmembership"></span></LEGEND>
                  &nbsp;<OBJECT id="lst_groupnames" name="lst_groupnames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filtersecuritygroup" name="txt_filtersecuritygroup">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_dgmembership>
                  <LEGEND><input type="checkbox" id="chk_dgmembership" name="chk_dgmembership" checked=True>Distribution Group Membership <span id="span_dgmembership"></span></LEGEND>
                  &nbsp;<OBJECT id="lst_dgnames" name="lst_dgnames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filterdgmembership" name="txt_filterdgmembership">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_managerlist>
                  <LEGEND><input type="checkbox" id="chk_managerlist" name="chk_managerlist" checked=True>Manager <span id="span_managerlist"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_managerlist" name="lst_managerlist" onDblClick="vbs:Submit_Form('ManagerList')">
                  
                  </select>
                  <br>Filter: <input type="text" size="40" id="txt_filtermanagerlist" name="txt_filtermanagerlist">
                  </fieldset>
                  <br><br>
                  <fieldset id=tr_subordinates>
                  <LEGEND><input type="checkbox" id="chk_subordinates" name="chk_subordinates" checked=True>Subordinates <span id="span_subordinates"></span></LEGEND>
                  &nbsp;<select size="8" id="lst_subordinates" name="lst_subordinates" onDblClick="vbs:Submit_Form('Subordinate')">
                  
                  </select>
                  </fieldset>
                  </td>
            </tr>
      </table>
 </body>

Open in new window

0
 
rejoinderCommented:
1. You gave me a code that can add users to Distribution and security groups. Can that code be added to the below. Code. So i can do both in one.

Done.
Added menu item under Tools to Add Users to Groups.  This points to the script attached.  Please name the script below as "Q_23768297.hta".
<head>
<title>User Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="User Information"
     BORDER="thin"
     SCROLL="yes"
     ID="oHTAAddUserToGroups"
>
<APPLICATION:HTA>
</head>
 
<script language="VBScript">
Dim strOU, strDomain, arrDomainNames
 
'Enter the OU you want to get groups from
strOU = "OU=Some OU,DC=xyz,DC=com"
 
'Enter the domain name where the users can be found
strDomain = "YOURDOMAIN"
 
Sub Window_OnLoad
    if strOU = "" then GetDomainNames
    FillGroupMembershipList
End Sub
 
Sub GetDomainNames
    set objRootDSE   = GetObject("LDAP://RootDSE")
    strBase          = "<LDAP://cn=Partitions," & _
                        objRootDSE.Get("ConfigurationNamingContext") & ">;"
    strFilter        = "(&(objectcategory=crossRef)(systemFlags=3));"
    strAttrs         = "name,trustParent,nCName,dnsRoot,distinguishedName;"
    strScope         = "onelevel"
    set objConn      = CreateObject("ADODB.Connection")
    objConn.Provider = "ADsDSOObject"
    objConn.Open "Active Directory Provider"
    set objRS = objConn.Execute(strBase & strFilter & strAttrs & strScope)
    objRS.MoveFirst
    
    set arrDomainNames     = CreateObject("Scripting.Dictionary")
    set dicDomainHierarchy = CreateObject("Scripting.Dictionary")
    set dicDomainRoot      = CreateObject("Scripting.Dictionary")
    
    while not objRS.EOF 
        dicDomainRoot.Add objRS.Fields("name").Value, objRS.Fields("nCName").Value
        if objRS.Fields("trustParent").Value <> "" then
            arrDomainNames.Add objRS.Fields("name").Value, 0
            set objDomainParent = GetObject("LDAP://" & objRS.Fields("trustParent").Value)
            dicDomainHierarchy.Add objRS.Fields("name").Value,objDomainParent.Get("name")
       else 
            arrDomainNames.Add objRS.Fields("name").Value, 1
       end if
       objRS.MoveNext
    wend
    for each strDomain in arrDomainNames
        'msgbox strDomain
    next
End Sub
 
Sub FillGroupMembershipList
 
    set newOption = document.createElement("OPTION")
    newOption.Text = ""
    newOption.Value = ""
    lst_distributiongroupnames.Add newOption
 
    set newOption = document.createElement("OPTION")
    newOption.Text = ""
    newOption.Value = ""
    lst_groupnames.Add newOption
 
    Set adoCommand = CreateObject("ADODB.Command")
    Set adoConnection = CreateObject("ADODB.Connection")
    adoConnection.Provider = "ADsDSOObject"
    adoConnection.Open "Active Directory Provider"
    adoCommand.ActiveConnection = adoConnection
    strSearchField = "(distinguishedname=*)"
    if strOU = "" then
        for each Domain in arrDomainNames
            strBase = "<LDAP://" & Domain & ">"
            strFilter = "(&(objectCategory=group)" & strSearchField & ")"
            strAttributes = "cn,distinguishedName,primaryGroupID,samaccounttype"
            strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
            adoCommand.CommandText = strQuery
            adoCommand.Properties("Page Size") = 100
            adoCommand.Properties("Timeout") = 30
            adoCommand.Properties("Cache Results") = False
            adoCommand.Properties("Sort On") = "cn"
            Set adoRecordset = adoCommand.Execute
            If Not adoRecordset.EOF Then
                Do Until adoRecordset.EOF
                    strNTName            = adoRecordset.Fields("cn").Value
                    strGroupType         = adoRecordset.Fields("samaccounttype").Value
                    strPrimary           = adoRecordset.Fields("primaryGroupID").Value
                    strdistinguishedName = adoRecordset.Fields("distinguishedname").Value
                    Select Case strGroupType
                        Case 2,268435457,4,536870913,8,268435457 'Distribution Groups
                            set newOption = document.createElement("OPTION")
                            newOption.Text = strNTName
                            newOption.Value = strPrimary & ";" & strdistinguishedName
                            lst_distributiongroupnames.Add newOption
                        Case -2147483646,268435456,-2147483644,536870912,-2147483640,268435456 'Security Groups
                            set newOption = document.createElement("OPTION")
                            newOption.Text = strNTName
                            newOption.Value = strPrimary & ";" & strdistinguishedName
                            lst_groupnames.Add newOption
                    End Select
                    adoRecordset.MoveNext
                Loop
            End If
        next
    else
        strBase = "<LDAP://" & strOU & ">"
        strFilter = "(&(objectCategory=group)" & strSearchField & ")"
        strAttributes = "cn,distinguishedName,primaryGroupID,samaccounttype"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        adoCommand.CommandText = strQuery
        adoCommand.Properties("Page Size") = 100
        adoCommand.Properties("Timeout") = 30
        adoCommand.Properties("Cache Results") = False
        adoCommand.Properties("Sort On") = "cn"
        Set adoRecordset = adoCommand.Execute
        If Not adoRecordset.EOF Then
            Do Until adoRecordset.EOF
                strNTName            = adoRecordset.Fields("cn").Value
                strGroupType         = adoRecordset.Fields("samaccounttype").Value
                strPrimary           = adoRecordset.Fields("primaryGroupID").Value
                strdistinguishedName = adoRecordset.Fields("distinguishedname").Value
                Select Case strGroupType
                    Case 2,268435457,4,536870913,8,268435457 'Distribution Groups
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_distributiongroupnames.Add newOption
                    Case -2147483646,268435456,-2147483644,536870912,-2147483640,268435456 'Security Groups
                        set newOption = document.createElement("OPTION")
                        newOption.Text = strNTName
                        newOption.Value = strPrimary & ";" & strdistinguishedName
                        lst_groupnames.Add newOption
                End Select
                adoRecordset.MoveNext
            Loop
        End If
    End if
    adoRecordset.Close
    Set adoRecordset = Nothing
    adoConnection.Close
End Sub
 
Sub Submit_Form
    on error resume next
    strUserNames = txt_usernames.Value
    if strUserNames = "" then
        msgbox "Cannot proceed - please input user name(s)"
    else
        For i = 1 to (lst_distributiongroupnames.Options.Length - 1)
            If (lst_distributiongroupnames.Options(i).Selected) Then
                arrGroupNames     = split(lst_distributiongroupnames.Options(i).Value,";")
                strprimaryGroupID = arrGroupNames(0)
                strGroupDN        = arrGroupNames(1)
            End If
        Next
        if NOT IsArray(arrGroupNames) then
            For i = 1 to (lst_groupnames.Options.Length - 1)
                If (lst_groupnames.Options(i).Selected) Then
                    arrGroupNames     = split(lst_groupnames.Options(i).Value,";")
                    strprimaryGroupID = arrGroupNames(0)
                    strGroupDN        = arrGroupNames(1)
                End If
            Next
        End if
        arrUserNames = split(strUserNames,";")
        for each strUser in arrUserNames
            strUser = trim(strUser)
            strUserDN = GetDistinguishedNameofUser(s