Setting the Administrator and user account passwords.


I have designed a very nice function to password the current user account. The name of the user account is called by function ::getenv("USERNAME");

The core is function NetUserSetInfo, which at the level code 1003 ensures that the given password is entered into the function.

void SetSystemPassword(::std::string input_password)
::std::string input_username[] = {::getenv("USERNAME"), "Administrator"};

int input_username_size = sizeof(input_username)/sizeof(::std::string);

::LPWSTR password = A2W_EX(input_password.c_str(), input_password.length());

for(int i = 0; i<input_username_size; i++)
::LPWSTR username = A2W_EX(input_username[i].c_str(), input_username[i].length());

USER_INFO_1003 usriSetPassword;

usriSetPassword.usri1003_password = password;
::NetUserSetInfo(NULL, username, UserInfoPassword, (::LPBYTE)&usriSetPassword, NULL);

The function is called from main:

#include "WinAPI.h" //https://

#define UserInfoPassword 1003
int _cdecl main(void) { SetSystemPassword ("diallix"); return 0; }





The whole function is built into header WinAPI.h WinAPI.h

#include "WinAPI.h" //

int _cdecl main (void) 
return 0; }