Access is denied when accessing PrincipalContext on a remote machine with a known good login

I am trying to add a domain account to a group of remote computers. The problem I am facing is that when I try to connect to a remote PrincipleContext computer, it gives me a message about denied access, but I connect to it as the local administrator of the remote machine. When I try to access it, although I get "Access denied . " I know that the login is correct, because if I change it, instead I get the wrong passwords / username.

An administrator account is a real administrator account, and I can enter the local block with an account, and I have full administrator access, I can add users as needed without any problems to the Administrators group. Any ideas that might make him report access are denied when trying to do it remotely?

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); } 
+4
source share
1 answer

Well! I have a server with a configured domain and AD. Name it A. I need to connect to it from another PC B , which is part of the network (however it is not associated with a domain).

So, for this case, the only change was made to the line -

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

So here is the code -

 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(); } 

And when testing, it worked smoothly.

0
source

All Articles