在具有已知良好登录的远程计算机上访问PrincipalContext时,访问被拒绝

Zip*_*per 5 c# directoryservices active-directory

我正在尝试将域帐户添加到远程计算机的管理员组.我遇到的问题是,当我尝试实际连接到远程机器PrincipleContext时,它给了我一个访问被拒绝的消息,但我作为远程机器本地管理员连接.当我试图访问它虽然我得到"访问被拒绝".我知道登录是正确的,因为如果我更改它,我会收到错误的密码/用户名错误.

管理员帐户是真正的管理员帐户,我可以使用该帐户登录到本地方框,并且我具有完全管理员权限,我可以根据需要向管理员组添加用户而不会出现任何问题.尝试远程执行此操作时,任何会导致其报告Access的想法都会被拒绝?

try
      {
        using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, "SERVER_IP_HERE", null, ContextOptions.Negotiate, @"RemoteMachineNameHere\Administrator", "MyPassword"))
        {
          //Get an access denied error here trying to connect to the Context
          GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "Administrators");
          PrincipalContext dom1PC = new PrincipalContext(ContextType.Domain, "FQDNOFDomainHere");
          var me = UserPrincipal.FindByIdentity(dom1PC, IdentityType.SamAccountName, @"MyUserName");
          group.Members.Add(me);
          group.Save();
        }
      }
      catch (System.DirectoryServices.DirectoryServicesCOMException E)
      {
        Console.WriteLine(e);

      } 
Run Code Online (Sandbox Code Playgroud)

Vik*_*ini -1

出色地!我有一台配置了域并安装了 AD 的服务器。我们将其命名为A。我需要从属于网络一部分的其他 PC B连接到它(但它没有加入域)

所以对于这种情况,唯一的改变是在线完成的 -

using (PrincipalContext pc = new PrincipalContext(ContextType.Machine, "SERVER_IP_HERE", null, ContextOptions.Negotiate, @"DomainNameOfRemoteMachineHere\Administrator", "MyPassword")
Run Code Online (Sandbox Code Playgroud)

所以这是代码 -

static void Main()
    {
        try
        {
            using (PrincipalContext pcRoot = new PrincipalContext(ContextType.Machine, "IP_Address", null, ContextOptions.Negotiate, @"domainNameHere\Administrator", "SomePass"))
            {
                //Get an access denied error here trying to connect to the Context
                var group = GroupPrincipal.FindByIdentity(pcRoot, "Administrators");
                var pc = new PrincipalContext(ContextType.Domain, "FQDNOFDomainHere");
                var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "vssaini");

                if (group == null)
                {
                    Console.WriteLine("Group not found.");
                    return;
                }

                if (user == null)
                    Console.WriteLine("User not found.");
                else
                    group.Members.Add(user);

                group.Save();
            }
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc);
        } 

        // Wait for output
        Console.ReadKey();
    }
Run Code Online (Sandbox Code Playgroud)

并且在测试过程中运行顺利。