ASP.NET C# GetObject

Discussion in 'ASP .Net' started by LamSoft, Jun 6, 2007.

  1. LamSoft

    LamSoft 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
     
    LamSoft, Jun 6, 2007
    #1
    1. Advertising

  2. On Jun 6, 6:22 am, "LamSoft" <[nospam]> wrote:
    > 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();
     
    Alexey Smirnov, Jun 6, 2007
    #2
    1. Advertising

  3. LamSoft

    LamSoft Guest

    May I know how to know the return code?
    Thank you
    "Alexey Smirnov" <> wrote in message
    news:...
    > On Jun 6, 6:22 am, "LamSoft" <[nospam]> wrote:
    >> 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();
    >
     
    LamSoft, Jun 6, 2007
    #3
  4. On Jun 6, 9:55 am, "LamSoft" <[nospam]> wrote:
    > May I know how to know the return code?
    > Thank you"Alexey Smirnov" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > On Jun 6, 6:22 am, "LamSoft" <[nospam]> wrote:
    > >> 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();- Hide quoted text -

    >
    > - 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;
    }
     
    Alexey Smirnov, Jun 6, 2007
    #4
  5. LamSoft

    LamSoft Guest

    Thanks a lot
    "Alexey Smirnov" <> wrote in message
    news:...
    > On Jun 6, 9:55 am, "LamSoft" <[nospam]> wrote:
    >> May I know how to know the return code?
    >> Thank you"Alexey Smirnov" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > On Jun 6, 6:22 am, "LamSoft" <[nospam]> wrote:
    >> >> 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();- Hide quoted text -

    >>
    >> - 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;
    > }
    >
     
    LamSoft, Jun 6, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ]-[aTc]-[

    Getobject C# Equevlent

    ]-[aTc]-[, Jul 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    11,262
    Craig Deelsnyder
    Jul 17, 2004
  2. Delia
    Replies:
    4
    Views:
    810
    Michael Borgwardt
    Nov 19, 2004
  3. LittlePython

    Try/Except for ADSI GetObject

    LittlePython, May 31, 2006, in forum: Python
    Replies:
    1
    Views:
    493
    Roger Upole
    Jun 1, 2006
  4. pardesiya

    GetObject error in ASP.NET

    pardesiya, Jul 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    540
    pardesiya
    Jul 19, 2007
  5. Rich

    Does GetObject work with ASP?

    Rich, Nov 11, 2003, in forum: ASP General
    Replies:
    10
    Views:
    514
    Aaron Bertrand - MVP
    Nov 14, 2003
Loading...

Share This Page