更改计算机名未知错误,尝试设置本地计算机帐户密码时出现未知错误(0x80005000)(Unknown error (0x80005000) when trying to set local mach...

I am writing a csharp windows form application which attempts to check for the existence of a local account and if found set the password on it. A couple of key points:

I'm doing this for local accounts - NOT Active Directory accounts. The machines are not members of a windows AD domain.

I HAVE to use setpassword not changepassword as change password requires you to know the previous password which in some cases I do not. Setpassword is supposed to allow you to select a new password without having to know the old one

The application will be run by approximately 50 users using a variety of OS's from Windows XP all the way up to Windows Server 2008 R2. Because I can't predict what operating system and version of .net will be available I have set my target framework as .net 2.0.

I am expecting my user to be running as an administrator presently so I don't think permissions are an issue. I can create uses just fine I just can't set 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 am receiving:

Unknown error (0x80005000)

OK

I can't figure out why I'm getting the above error and despite googling and searching stack overflow I can't find any explanation. Most examples I can find revolve around connecting to Active Directory - not local accounts. Or are using newer .net 4.0 features. I have to believe that if I can create an account I should be able to set the password on an account. Any ideas or suggestions on what I might be doing wrong?

Thanks Brad

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值