Unknown error (0x80005000) when trying to set the password for the local computer account

I am writing a csharp windows form application that tries to check if there is a local account and if set, set a password for it. A few key points:

  • I am doing this for local accounts - NOT Active Directory accounts. The machines are not part of the Windows AD domain.

  • I use setpassword not changepassword as the change password requires you to know the previous password, which in some cases I don't. Setpassword is supposed to allow you to choose a new password without knowing the old one.

  • The application will run by approximately 50 users using a variety of operating systems from Windows XP up to Windows Server 2008 R2. Since I cannot predict which operating system and .net version will be available, I set my target framework as .net 2.0.

  • I expect my user to be running as an administrator at this time, so I don't think permissions are an issue. I can create apps just fine, I just can't set a password on an existing account.

Here's my code:

    public void VerifiyAccount()
    {
        String username = "specialaccount";
        String password = "SuperSecretPassw0rd!";

        if (CheckIfAccountExists(username))
        {
            MessageBox.Show("User Account all ready exists.");
            SetUserPassword(password);

        }
        else
        {
            MessageBox.Show("User Account does not exist");
            CreateUserAccount(username, password);
        }
    }

    public void SetUserPassword(string newPassword)
    {
        try
        {
            DirectoryEntry hostMachineDirectory = new DirectoryEntry("WinNT://" + Environment.MachineName + ", specialaccount");
            hostMachineDirectory.Invoke("SetPassword", newPassword);
            hostMachineDirectory.CommitChanges();
            hostMachineDirectory.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

      

Here's the error I'm getting:


Unknown error (0x80005000)

OK

I cannot figure out why I am getting the above error, and despite googling and stack overflow, I cannot find any explanation. Most of the examples I can find relate to connecting to Active Directory, not local accounts. Or use the newer .net 4.0 features. I have to believe that if I can create an account, I would have to set a password on the account. Any ideas or suggestions on what I might be doing wrong?

Thanks Brad

+3


source to share


1 answer


I am running similar obfuscation errors when using ActiveDirectory libraries. What I have found very useful is using Microsoft Network Monitor to track messages sent to / from LDAP. Usually, the bug report is sent with much more detailed information.

EDIT . I would recommend the following to help you debug your communication problems:

  • Place a breakpoint and run the application where you are CommitChanges

  • Run Microsoft Network Monitor (Start Capture)
  • Execute line CommitChanges

  • Stop current capture in Microsoft Network Monitor


At this point, you can scroll through the messages to find out where your calls originated.

EDIT2 : Here's a link to DirectoryEntry.Path . It renders the WinNT formatting to connect to the user as:

WinNT: // <domain name> / <computer name> / <user name>

+2


source







All Articles