gpt4 book ai didi

c# - 为什么 DirectoryEntry ("WinNT://") 不显示组所有人?

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:06 27 4
gpt4 key购买 nike

下面的函数(应该)列出本地机器上的所有组。
现在的问题是:为什么“所有人”组没有出现?
如果我以用户身份更改目录权限,我会看到“所有人”组,因此它一定在某处。

    Public Shared Function GetAllGroups() As DataTable
Return GetAllGroups(System.Environment.MachineName)
End Function


' Tools.Permissions.Local.GetAllGroups() '
Public Shared Function GetAllGroups(ByVal strDomain As String) As DataTable
Dim dt As New DataTable
Dim dr As DataRow = Nothing

Try
Dim bException As Boolean = False
Dim deLocalMachine As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry("WinNT://" + strDomain)
'Dim deRootObject As System.DirectoryServices.DirectoryEntry = GetDirectoryEntry(strPath, strUserName, strPassword, bException) '
If bException Then
Return Nothing
End If


For Each child As System.DirectoryServices.DirectoryEntry In deLocalMachine.Children
Try

If StringComparer.OrdinalIgnoreCase.Equals(child.SchemaClassName, "group") Then

If Not dt.Columns.Contains("Members") Then
dt.Columns.Add("Members", GetType(System.String))
End If

For Each strPropertyName As String In child.Properties.PropertyNames
If Not dt.Columns.Contains(strPropertyName) Then
dt.Columns.Add(strPropertyName, GetType(System.String))
End If
Next strPropertyName

dr = dt.NewRow

Dim strMembers As String = ""
For Each member As Object In DirectCast(child.Invoke("Members"), IEnumerable)
Using memberEntry As New System.DirectoryServices.DirectoryEntry(member)

Try
strMembers += memberEntry.Properties("Name").Value.ToString() + Environment.NewLine
Console.WriteLine(memberEntry.Path)
Catch exFixMeIsNotNullNotWorking As Exception

End Try

End Using
Next

dr("Members") = strMembers

For Each strPropertyName As String In child.Properties.PropertyNames

If StringComparer.OrdinalIgnoreCase.Equals(strPropertyName, "objectSid") Then
Dim strSID As String = ""
Try
Dim sidThisSid As New System.Security.Principal.SecurityIdentifier(child.Properties(strPropertyName).Value, 0)
strSID = sidThisSid.ToString()
' http://stackoverflow.com/questions/1040623/convert-a-username-to-a-sid-string-in-c-net '
' NTAccount ntAccount = (NTAccount)sid.Translate( typeof( NTAccount ) ); '
' Dim ntAccount As Security.Principal.NTAccount = CType(sidThisSid.Translate(GetType(Security.Principal.NTAccount)), Security.Principal.NTAccount) '
Catch ex As Exception

End Try

dr(strPropertyName) = strSID
Else
dr(strPropertyName) = child.Properties(strPropertyName).Value.ToString()
End If



Next strPropertyName
dt.Rows.Add(dr)

End If

Catch ex As Exception ' Don't finish just because one fails
Console.WriteLine(ex.Message.ToString & vbLf & vbLf & ex.StackTrace.ToString, MsgBoxStyle.Critical, "FEHLER ...")
End Try
Next
Catch ex As Exception
Console.WriteLine(ex.Message.ToString & vbLf & vbLf & ex.StackTrace.ToString, MsgBoxStyle.Critical, "FEHLER ...")
End Try

Return dt
End Function ' ListEverything

最佳答案

Everyone 组不是标准组,而是隐式组或内置主体。如果您打开本地的“用户和组”,您也不会在其中看到它。其他“组”也是如此,例如 Authenticated Users。如果你想访问这些,你需要使用 System.Security.Principal.WellKnownSidType枚举。这Windows 2008 article也确实与旧版本的 Windows 相关。

关于c# - 为什么 DirectoryEntry ("WinNT://") 不显示组所有人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5041988/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com