Resolve SID to local group name

Antworten
Benutzeravatar
Sebastian
Administrator
Beiträge: 650
Registriert: Di 28. Mai 2013, 20:45
Wohnort: Krefeld
Kontaktdaten:

Resolve SID to local group name

Beitrag von Sebastian » So 10. Mai 2020, 21: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