How to reset windows local user passwd, without knowing its current passwd

The following code shows how to reset windows local user passwd by using Win32 API NetUserSetInfo(),
the windows user who call this procedure should have administrator previlege on the local computer, other wise it will fail.

在我本机测试过了,好使!




Example: 
   
void  CBW_AD_migration_helperDlg::OnBnClickedBtnsetadminpassword()
{
    
if(TRUE==winadminapi::myNetUserSetInfo(L"Administrator",L"passwordxxxx"))
        MessageBox(
"password for local Administrator set");

}


/
// Filename: winadminapi.h
class  winadminapi
{
public:
    winadminapi(
void);
    
~winadminapi(void);
    
static BOOL myNetUserSetInfo(LPCWSTR lpUsername,LPWSTR lpPasswd);
}
;

/
// Filename: winadminapi.cpp

winadminapi::winadminapi(void)
{
}

winadminapi::~winadminapi(void)
{
}

/*
 * Function: set windows local user password without knowing its current passwd
 * Input: Username, Passwd
 * Return: TRUE if successfully set the password for the specified local user, FALSE otherwise
 
*/


BOOL winadminapi::myNetUserSetInfo(LPCWSTR lpUsername,LPWSTR lpPasswd)
{
    USER_INFO_1003 ui;
    NET_API_STATUS nStatus;
    ui.usri1003_password  
= lpPasswd;
    nStatus  
= NetUserSetInfo(
        NULL,        
//LPCWSTR servername,    when NULL the local computer is used
        lpUsername,    //    LPCWSTR username,
        1003,        //    DWORD level,
        (LPBYTE) &ui,    //    LPBYTE buf,
        NULL        //    LPDWORD parm_err
        );
    
if (nStatus == NERR_Success)
        
return TRUE;
    
else
        
return FALSE;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值