我正在尝试将域帐户添加到远程计算机的管理员组.我遇到的问题是,当我尝试实际连接到远程机器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);
}