使用 System.DirectoryServices.AccountManagement 列出本地管理员不会检索域用户
我正在尝试远程列出本地管理员组的成员。以下代码仅返回属于管理员组成员的本地帐户 - 根本不返回域组或个人帐户(例如,BLAH\Domain Admins 或 BLAH\yajohn)。
有人有主意吗?
Public Function listLocalAdmins(ByVal machinename As String, ByVal creduname As String, ByVal credpass As String) As String
Try
Dim mctx As New PrincipalContext(ContextType.Machine, machinename, creduname, credpass)
Dim lcladmins As GroupPrincipal = GroupPrincipal.FindByIdentity(mctx, IdentityType.Name, "Administrators")
Dim pc As PrincipalCollection = lcladmins.Members
Dim r As New StringBuilder
For Each p As Principal In pc
r.Append("Name:->" & p.Name.ToString & vbCrLf)
Next
Return r.ToString
Catch ex As Exception
Return ex.Message
End Try
End Function
感谢您的任何反馈。
I'm trying to remotely list members of the local Administrators group. The following code returns only local accounts which are members of the admin group - no domain groups or individual accounts are returned at all (BLAH\Domain Admins or BLAH\yajohn, for instance).
Anyone have an idea?
Public Function listLocalAdmins(ByVal machinename As String, ByVal creduname As String, ByVal credpass As String) As String
Try
Dim mctx As New PrincipalContext(ContextType.Machine, machinename, creduname, credpass)
Dim lcladmins As GroupPrincipal = GroupPrincipal.FindByIdentity(mctx, IdentityType.Name, "Administrators")
Dim pc As PrincipalCollection = lcladmins.Members
Dim r As New StringBuilder
For Each p As Principal In pc
r.Append("Name:->" & p.Name.ToString & vbCrLf)
Next
Return r.ToString
Catch ex As Exception
Return ex.Message
End Try
End Function
Thanks for any feedback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之前发过帖子,但发现它并没有解决你的问题。我无法使用 AccountManagement 来执行您想要的操作。我可以使用 DirectoryServices,也许这会有所帮助。
I posted earlier, but found out it didn't resolve your issue. I was not able to use AccountManagement to do what you wanted. I was able to use DirectoryServices though, maybe this will help.