ASP.NET C# GetObject

L

LamSoft

I want to write a ASPX C# to change the password of a user account on
standalone computer,

I have the ASP code on my friend, but I don't know how to convert them to
ASP.NET C#.

Is there any reference on the web? Thank you.

ASP Code Reference:
Set UsrObj = GetObject("WinNT://" & ServerName & "/" & UserName ,user)
UsrObj.SetPassword NewPwd
UsrObj.SetInfo

If Err.Number = 0 Then
OutMsg("The password of " & UserName & " was successfully changed.")
Else
OutMsg("Unexpected Error: " & Err.Number & ", Please contact the
webmaster.")
End If
 
G

Guest

I want to write a ASPX C# to change the password of a user account on
standalone computer,

I have the ASP code on my friend, but I don't know how to convert them to
ASP.NET C#.

Is there any reference on the web? Thank you.

ASP Code Reference:
Set UsrObj = GetObject("WinNT://" & ServerName & "/" & UserName ,user)
UsrObj.SetPassword NewPwd
UsrObj.SetInfo

If Err.Number = 0 Then
OutMsg("The password of " & UserName & " was successfully changed.")
Else
OutMsg("Unexpected Error: " & Err.Number & ", Please contact the
webmaster.")
End If

To access WinNT provider intetrface you should use
System.DirectoryServices namespace

using System.DirectoryServices;

DirectoryEntry myDirectoryEntry;

myDirectoryEntry = new DirectoryEntry(@"WinNT://" + ServerName + "/" +
UserName + ",User");
myDirectoryEntry.Invoke("setPassword", NewPwd);
myDirectoryEntry.CommitChanges();
 
L

LamSoft

May I know how to know the return code?
Thank you
Anon User said:
To access WinNT provider intetrface you should use
System.DirectoryServices namespace

using System.DirectoryServices;

DirectoryEntry myDirectoryEntry;

myDirectoryEntry = new DirectoryEntry(@"WinNT://" + ServerName + "/" +
UserName + ",User");
myDirectoryEntry.Invoke("setPassword", NewPwd);
myDirectoryEntry.CommitChanges();
 
G

Guest

May I know how to know the return code?









- Show quoted text -

You should catch an exception

try
{
myDirectoryEntry = new DirectoryEntry(@"WinNT://" + ServerName + "/"
+
UserName + ",User");
myDirectoryEntry.Invoke("setPassword", NewPwd);
myDirectoryEntry.CommitChanges();
}
catch (Exception e)
{
OutMsg("Unexpected Error: " & e.ToString() & ", Please contact the
webmaster.");
return;
}
 
L

LamSoft

Thanks a lot
Anon User said:
You should catch an exception

try
{
myDirectoryEntry = new DirectoryEntry(@"WinNT://" + ServerName + "/"
+
UserName + ",User");
myDirectoryEntry.Invoke("setPassword", NewPwd);
myDirectoryEntry.CommitChanges();
}
catch (Exception e)
{
OutMsg("Unexpected Error: " & e.ToString() & ", Please contact the
webmaster.");
return;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top