Nos provee de una interfaz grafica que nos permite modificar la información del usuario.
<head>
<title>Staff details editor</title>
<HTA:APPLICATION
APPLICATIONNAME="Staff details editor"
SCROLL="YES"
SINGLEINSTANCE="YES"
>
</head>
<script language="VBScript">
Const strDomainPath = "ou=Staff,dc=Contoso,dc=com"
Sub StaffSelected
strStaffLDAP = StaffDropDown.Value
Set objUser = GetObject(strStaffLDAP)
' If the employee has a manager defined, prefix the string with "LDAP://" to make it easier to compare against ADsPath strings
If objUser.Manager<>"" Then
strManagerLDAP = "LDAP://" & objUser.Manager
End If
' Build the form HTML
strSpanHTML = "<p>Job title: <input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "JobTitle" & Chr(34) & " size=50><br>"
strSpanHTML = strSpanHTML & "Manager: <select name=" & Chr(34) & "ManagerDropDown" & Chr(34) & "></select><br>"
strSpanHTML = strSpanHTML & "Department: <input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "Department" & Chr(34) & "></p>"
strSpanHTML = strSpanHTML & "<p><input class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Save changes" & Chr(34) & " onClick=" & Chr(34) & "SaveButton" & Chr(34) & "> "
strSpanHTML = strSpanHTML & "<input class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & " onClick=" & Chr(34) & "CancelButton" & Chr(34) & "></p>"
' Plonk it onto the page
Output.InnerHTML = strSpanHTML
' Build the Manager drop-down list
' We can do this by copying the staff list, since it is going to be the same list of names
For Each objOption in StaffDropDown.Options
Set objManager = Document.CreateElement("OPTION")
objManager.Text = objOption.Text
objManager.Value = objOption.Value
ManagerDropDown.Add(objManager)
If objManager.Value = strManagerLDAP Then
objManager.Selected = True
End If
Next
' Fill in the other missing details
JobTitle.Value = objUser.title
Department.Value = objUser.department
End Sub
Sub SaveButton
' Just write all three values out
strStaffLDAP = StaffDropDown.Value
Set objUser = GetObject(strStaffLDAP)
If JobTitle.value <> "" Then
objUser.Put "title", JobTitle.Value
End If
If Department.value <> "" Then
objUser.Put "department", Department.Value
End If
' Manager is slightly more tricky as we have to strip the LDAP:// bit off the ADsPath
strManager = ManagerDropDown.Value
If strManager <> "" Then
strManager = Mid(strManager, 8)
End If
objUser.Put "manager", strManager
CancelButton
On Error Resume Next
objUser.SetInfo
If Err.Number = 0 Then
Output.InnerHTML = "<p>User information updated successfully.</p>"
Else
Output.InnerHTML = "<P>Error while setting user information: " & Err.Description & "</p>"
End If
End Sub
Sub CancelButton
Output.InnerHTML = ""
' Reset the staff picker to the Select... option
bolSelected = True
For Each objOption in StaffDropDown.Options
objOption.Selected = bolSelected
bolSelected = False
Next
End Sub
Sub Window_Onload
Const ADS_SCOPE_SUBTREE = 2
self.ResizeTo 439,216
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT Name, ADsPath FROM 'LDAP://" & strDomainPath & "' WHERE objectCategory='user' ORDER BY Name"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objOption = Document.createElement("OPTION")
objOption.Text = objRecordSet.Fields("Name").Value
objOption.Value = objRecordSet.Fields("ADsPath").Value
StaffDropDown.Add(objOption)
objRecordSet.MoveNext
Loop
End Sub
</script>
<body>
Name: <select name="StaffDropDown" onChange="StaffSelected">
<option value="">Select ...</option>
</select>
<span id="Output"></span>
</body>