Suivant le formulaire que l'on désire réaliser, il peut être utile d'aller lire les informations se trouvant sur le serveur exchange, p.ex:
- les propriétés d'un compte
- le calendrier d'un compte
Avec vbscript cela est possible en utilisant
- LDAP pour la lecture des propriétés
- webdav pour la lecture du calendrier.
Exchange regroupe 4 types d'information:
- Service Anuaire (directory service)
- Banque d'information (information store)
- Agent de transfert des message(message transfer agent)
- Surveillance du système(system attendant)
Lecture des champs des propriétés d'un compte ExchangeLes propriétés d'un compte se trouve dans le service anuaire. On peut aller lire ces informations grâce à LDAP (il faut bien entendu que celui-ci soit activé dans exchange).
Voici le code miraculeux :
Dim MyUser
Dim HomeServer
Set MyUser = GetObject("LDAP://CN=Administrator,CN=Users,DC=sunnydale,DC=muni")
HomeServer = myUser.Get("msExchHomeServerName")
La ligne "
LDAP://CN=Administrator,CN=Users,DC=sunnydale,DC=muni" permet d'aller lire le compte désiré. modifier la ligne pour correspondre à l'arborescence de votre serveur exchange.
La ligne "
HomeServer = myUser.Get("msExchHomeServerName")" permet d'extraire une information du compte. Si, par exemple, on veut extraire le champ "info" d'un compte, on remplace "msExchHomeServerName" par "info".
Remarque :
Pour avoir cet accès, il faut préalablement que le serveur Exchange permette l'accès lecture (et écriture) sur le champ du compte.
Lecture du calendrier d'un compte exchangePour pouvoir lire ces informations avec webdav, il faut avoir :
- le lien http du compte
- le domaine
- le nom d'utilisateur du compte
- le mot de passe
Le script est définit dans la msdn2 :
http://msdn2.microsoft.com/en-us/library/aa123570.aspx voici le fameux code à enregistrer avec l'extension *.vbs
Option Explicit
' Variables.
Dim strCalendarURI ' As String
Dim reqDoc ' As Msxml2.DOMDocument
Dim resDoc ' As Msxml2.DOMDocument
Dim pi ' As IXMLDOMProcessingInstruction
Dim strPassword ' As String
Dim strUserName ' As String
Dim searchrequestNode ' As IXMLDOMNode
Dim sqlNode ' As IXMLDOMNode
Dim strQuery ' As String
Dim queryNode ' As IXMLDOMText
Dim req ' As MSXML2.XMLHTTP
Dim objSubjectNodeList ' As IXMLDOMNodeList
Dim objLocationNodeList ' As IXMLDOMNodeList
Dim objStartTimeNodeList ' As IXMLDOMNodeList
Dim objEndTimeNodeList ' As IXMLDOMNodeList
Dim objBusyStatusNodeList ' As IXMLDOMNodeList
Dim objInstanceTypeNodeList ' As IXMLDOMNodeList
Dim objNode ' As IXMLDOMNode
Dim i ' As Integer
Dim strInstanceType ' As String
' Initialize variables.
strUserName = "Domain\UserName"
strPassword = "!Password"
strCalendarURI = "http://server/exchange/username/calendar/"
set reqDoc = createobject("microsoft.xmldom")
set resDoc = createobject("microsoft.xmldom")
set pi = reqDoc.createProcessingInstruction("xml","version=""1.0""")
' Append processing instruction node to the DOM document.
reqDoc.appendChild pi
' Create the DAV:searchrequest node and set it
' to the root element of the document.
set searchrequestNode = reqDoc.createNode(1,"searchrequest","DAV:")
set reqDoc.documentElement = searchrequestNode
' Create the DAV:sql node and append it to the root element.
set sqlNode = reqDoc.createNode(1,"sql","DAV:")
searchrequestNode.appendChild sqlNode
' Build the SQL query.
strQuery = "SELECT ""urn:schemas:calendar:location"", ""urn:schemas:httpmail:subject"", "
strQuery = strQuery & " ""urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", "
strQuery = strQuery & " ""urn:schemas:calendar:busystatus"", ""urn:schemas:calendar:instancetype"" "
strQuery = strQuery & " FROM Scope('SHALLOW TRAVERSAL OF """ & strCalendarURI & """') "
strQuery = strQuery & "WHERE NOT ""urn:schemas:calendar:instancetype"" = 1 "
strQuery = strQuery & "AND ""DAV:contentclass"" = 'urn:content-classes:appointment' "
strQuery = strQuery & "AND ""urn:schemas:calendar:dtstart"" > '2003/06/01 00:00:00' "
strQuery = strQuery & "ORDER BY ""urn:schemas:calendar:dtstart"" ASC"
' Create the SQL query textnode and append it to document.
set queryNode = reqDoc.createTextNode(strQuery)
sqlNode.appendChild queryNode
' Create the XMLHTTP object.
set req = createobject("msxml2.xmlhttp")
' Specify the SEARCH method, the URL, that the request will be sent synchronously,
' the user name, and the password.
req.open "SEARCH", strCalendarURI, false, strUserName, strPassword
' Set the Content-Type header to "text/xml".
req.setrequestheader "Content-Type", "text/xml"
' Send the SEARCH request.
req.send reqDoc
' An error occurred on the server.
If req.status >= 500 Then
' Display request status and status text.
wscript.echo "Status: " & req.status
wscript.echo "Status text: An error occurred on the server."
' Success. Display the item display names.
ElseIf req.status = 207 Then
' Display request status and status text.
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
' Get the XML response.
set resDoc = req.responseXML
' Build a list of the urn:schemas:httpmail:subject XML nodes,
' corresponding to the calendar item subjects returned in the search request.
' The urn:schemas:httpmail: namespace is typically
' assigned the e: prefix in the XML response body.
Set objSubjectNodeList = resDoc.getElementsByTagName("e:subject")
' Build a list of the urn:schemas:calendar:location XML nodes,
' corresponding to the calendar item locations returned in the search request.
' The urn:schemas:calendar: namespace is typically
' assigned the d: prefix in the XML response body.
Set objLocationNodeList = resDoc.getElementsByTagName("d:location")
' Build a list of the urn:schemas:calendar:dtstart XML nodes,
' corresponding to the calendar item start times returned in the
' search request.
Set objStartTimeNodeList = resDoc.getElementsByTagName("d:dtstart")
' Build a list of the urn:schemas:calendar:dtend XML nodes,
' corresponding to the calendar item end times returned in the
' search request.
Set objEndTimeNodeList = resDoc.getElementsByTagName("d:dtend")
' Build a list of the urn:schemas:calendar:busystatus XML nodes,
' corresponding to the calendar item busy statuses returned in the
' search request.
Set objBusyStatusNodeList = resDoc.getElementsByTagName("d:busystatus")
' Build a list of the urn:schemas:calendar:instancetype XML nodes,
' corresponding to the calendar item instance types returned in the
' search request.
Set objInstancetypeNodeList = resDoc.getElementsByTagName("d:instancetype")
If objSubjectNodeList.length > 0 Then
wscript.echo "Calendar items..."
' Loop through returned calendar items.
For i = 0 To (objSubjectNodeList.length -1)
' Display subject.
Set objNode = objSubjectNodeList.nextNode
wscript.echo " Subject: " & objNode.Text
' Display location.
Set objNode = objLocationNodeList.nextNode
wscript.echo " Location: " & objNode.Text
' Display start time.
Set objNode = objStartTimeNodeList.nextNode
wscript.echo " Start time: " & objNode.Text
' Display end time.
Set objNode = objEndTimeNodeList.nextNode
wscript.echo " End time: " & objNode.Text
' Display busy status.
Set objNode = objBusyStatusNodeList.nextNode
wscript.echo " Busy status: " & objNode.Text
' Display instance type.
Set objNode = objInstanceTypeNodeList.nextNode
strInstanceType = objNode.Text
If strInstanceType = "0" Then
wscript.echo " Instance type: 0-Single appointment"
ElseIf strInstanceType = "1" Then
wscript.echo " Instance type: 1-Master recurring appointment"
ElseIf strInstanceType = "2" Then
wscript.echo " Instance type: 2-Single instance, recurring appointment"
ElseIf strInstanceType = "3" Then
wscript.echo " Instance type: 3-Exception to a recurring appointment"
Else
wscript.echo " Instance type: Unknown"
End If
wscript.echo ""
Next
Else
wscript.echo "No calendar items found..."
End If
Else
' Display the status, status text, and response text.
wscript.echo "Status: " & req.status
wscript.echo "Status text: " & req.statustext
wscript.echo "Response text: " & req.responsetext
End If
' Clean up.
Set req = nothing