c# - How to check connection is made into a server when using PrincipalContext? -
i need change password of windows user in machine connected in same network. connecting machine using principalcontext
method, specified user , change password.
private bool changeuserpassword(string servername,string serverip,string adminusername, string adminuserpassword, string username, string newiispassword) { using (var context = new principalcontext(contexttype.machine, servername, adminusername, adminuserpassword)) using (var user = userprincipal.findbyidentity(context, identitytype.samaccountname, username)) { user.setpassword(newiispassword); user.save(); } }
the problem won't connection server when providing 'servername' works 'serverip' , vice versa. if connected context.connectedserver
show server name, if not showing unknown path or bad username error.
if connection not made use serverip parameter
using (var context = new principalcontext(contexttype.machine, serverip, adminusername, adminuserpassword))
for tried if( context.connectedserver != servername)
know connection not working , put above code inside it.but return error since there no connectedserver.
how can check connection server made or not?
your dns server may not configured on network. please use fqdn of machine name.
Comments
Post a Comment