Resolve SID to local group name

Antworten
Benutzeravatar
Sebastian
Administrator
Beiträge: 662
Registriert: Di 28. Mai 2013, 21:45
Wohnort: Monheim am Rhein
Kontaktdaten:

Resolve SID to local group name

Beitrag von Sebastian » So 10. Mai 2020, 22:51

Code: Alles auswählen

Imports System.DirectoryServices

[...]

    Public Function GetGroupNameBySID(ByVal strSID As String) As String
        Dim strReturnValue As String = Nothing

        Using SearchRoot As New DirectoryEntry
            Using LocalSearcher As New DirectorySearcher(SearchRoot)
                LocalSearcher.SearchScope = SearchScope.Subtree
                LocalSearcher.Filter = "(objectSid=" & strSID & ")"
                LocalSearcher.PropertiesToLoad.Add("objectSid")
                LocalSearcher.PropertiesToLoad.Add("sAMAccountName")


                Dim searchresultLocalGroup As SearchResult = LocalSearcher.FindOne
                If Not searchresultLocalGroup Is Nothing Then
                    strReturnValue = searchresultLocalGroup.Properties("sAMAccountName").Item(0).ToString()
                End If
            End Using
        End Using

        Return strReturnValue
    End Function

Antworten