将网络组添加到本地管理员组时找不到网络路径错误

Network Path not found error when adding a network group to local administrators group

我正在尝试将我们域中的网络组添加到机器上的本地管理员组。

我逐行调试,它找到了本地管理员组,它找到了网络组但是当它到达这一行时:

AdministratorsGrp.Members.Add(网络组)

它returns一个错误"The network path was not found"

如何解决这个错误,我在网上搜索了 30 分钟但找不到解决方案:(

到目前为止,这是我的函数:

Private Function AddAdminGroup() As Boolean
    Dim AdministratorsGrp As GroupPrincipal
    Dim NetworkGrp As GroupPrincipal

    Try
        Dim DomainCtx As New PrincipalContext(ContextType.Domain, "<domainname>", "<username>", "<pw>")

        'Find Local Administrators group by SID
        AdministratorsGrp = GroupPrincipal.FindByIdentity(DomainCtx, IdentityType.Sid, "S-1-5-32-544")

        'Find Desktop Managers group by Name on Domain
        NetworkGrp = GroupPrincipal.FindByIdentity(DomainCtx, IdentityType.Name, "<network group")

        'Add Desktop Managers group to Administrators Group
        AdministratorsGrp.Members.Add(DesktopMGRGrp)

        'Save Group
        AdministratorsGrp.Save()

        Return True
    Catch PrinEx As PrincipalExistsException
        Return True
    Catch ex As Exception

    End Try
    Return False
End Function

在此先感谢您提供的任何帮助!!

我通过更改此行解决了这个问题:

Dim DomainCtx As New PrincipalContext(ContextType.Domain, "<domainname>", "<username>", "<pw>")

Dim DomainCtx As New PrincipalContext(ContextType.Domain)

我不确定为什么,但提供域的凭据导致了问题。