Hello SunnyLiang
Check TCP/UDP 445 port is opened on your firewall. To connect to an AD server from outside a domain, you need the following ports to be opened : . TCP/UDP 389 (LDAP) . TCP 3268 (GC) . TCP/UDP 445 (SMB over IP)
DirectoryEntry.Invoke() requires AuthenticationType.Secure. What this means is that it needs to be able to authenticate the request via Kerberos or NTLM.
It attempts to use LDAPS (TCP 636) first, then falls back to CiFS (TCP445) if/when it times out or fails because of a missing or invalid certificate. If neither of these ports are open, it will fail with an "RPC Server unavailable" exception.
Additionally: Are you (or could you upgrade to) .NET 3.5? The AD integration for users, groups, computers has been massively improved in .NET 3.5 - check out the MSDN article Managing Directory Security Principals ( https:// docs. microsoft. com/en-us/archive/msdn-magazine/2008/january/managing-directory-security-principals-in-the-net-framework-3-5 ) in the .NET Framework 3.5 for details.
In your case, you could do something like:
// establish context for local machine
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
// find the "Administrator" account
UserPrincipal admin = UserPrincipal.FindByIdentity(ctx, "Administrator");
// set the password to a new value
admin.SetPassword("new-top-secret-password");
admin.Save();
---------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept as answer--