Want to get creator, lastmodifier, and other security info for an item in an event sink?


Want to get creator, lastmodifier, and other security info for an item in an event sink?


You can extract a considerable amount of security information using the http://schemas.microsoft.com/exchange/security/ namespace. The information returned is in XML, so individual elements need to be extracted from the XML.  The following
vb function  is an example that shows how to get security information.


‘———————————————————————————–
‘GetItemSecurityInfo
‘ This function extracts security information for an item using an
‘ DispInfo.EventRecord.  This can be used in an Event Sink from a method
‘ such as IExStoreSyncEvents_OnSyncSave.

‘ Input:
‘   ado_rec – This is a DispInfo.EventRecord (ado.record). The pEventInfo
‘      parameter from OnSyncSave, etc can be used.
‘   sSearchSIDType – Type of SID information – “creator”, “lastmodifier”, etc.
‘      Note: See http://schemas.microsoft.com/exchange/security/ Namespace
‘   sSearchValue – The specific value to return – “S:display_name”, etc
‘ Returns:
‘   If sSearchValue is not set to “” then
‘      The security information for the item is returned.
‘   else
‘      An XML String containing the SID information is returned.
‘ Note: if you run the code and check the value of sReturn, you will see an
‘   XML document that contains all of the returned items you can extract using
‘   the sSearchValue argument.
‘ Example call:
‘   sCreator = GetItemSecurityInfo(ado_rec, “creator”, “display_name”)
‘ Note: You will need to set a project reference to Microsoft XML, v4.0
‘ Note: You can download MSXML 4.0 SP2 fro the following link:
‘    MSXML 4.0 Service Pack 2 (Microsoft XML Core Services)
‘    <http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&displaylang=en>
‘ Note: for more info, go to:
‘    schemas.microsoft.com/exchange/security/ Namespace
‘    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_schema_security_namespace.asp
‘———————————————————————————–
Private Function GetItemSecurityInfo(ado_rec As ADODB.Record, sSearchSIDType As String, sSearchValue) As String
        Dim oDoc As New MSXML2.DOMDocument40
        Set oDoc = New MSXML2.DOMDocument40
        Dim oNodeList As IXMLDOMNodeList
        Dim oNode As IXMLDOMNode
       
        Dim sSearchValueW As String
        Dim sReturn As String     ‘ Return value
        Dim sXML As String        ‘ Holds the SID information in XML
       
        sXML = ado_rec.Fields(“http://schemas.microsoft.com/exchange/security/” & sSearchSIDType)
        oDoc.loadXML sXML       ‘Load the XML text conaining all the SID information
        ‘oDoc.Save “c:\test.xml”    ‘ Uncomment to save to file
       
        If sSearchValue <> “” Then
            sSearchValueW = “S:” & sSearchValue ‘ See the text returned into sXML for what S: refers to
            Set oNodeList = oDoc.getElementsByTagName(sSearchValueW)  ‘ Get to the value we are looking for
            Set oNode = oNodeList.nextNode
            sReturn = oNode.Text  ‘ OK, here it is
        Else
            sReturn = sXML
        End If
       
        GetItemSecurityInfo = sReturn
End Function

Comments (0)