Changing a limited user account in XP fails

Posted by javamonkey79 on Stack Overflow See other posts from Stack Overflow or by javamonkey79
Published on 2010-12-29T04:33:53Z Indexed on 2010/12/29 4:53 UTC
Read the original article Hit count: 309

Filed under:
|
|

I have the following:

using System;
using System.DirectoryServices.AccountManagement;
public class ChangePassword
{
   public static void Main()
   {    
    PrincipalContext context = new PrincipalContext(ContextType.Machine);
    UserPrincipal user = UserPrincipal.FindByIdentity(context, "someLimitedAccount");
    user.ChangePassword( "xxx", "zzz" );
   }
}

This works just fine with administrator accounts, but seems to crash like so when I try to change limited accounts in XP:

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
   at ChangePassword.Main()

Is what I am trying to do possible? If so, how?

EDIT #1:
I added the following:
Console.WriteLine( "user: " + user );

Below this line:
UserPrincipal user = UserPrincipal.FindByIdentity(context, "someLimitedAccount");

And I get this:
user:

It doesn't look like user is null when I print it, but then again I'm not really a .Net guy - I seem to remember this being expected behavior.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET