void __fastcall TTFPrinc2::btnChangeClick(TObject *Sender)
{
#define MAX_LENGTH 32
#define MAX_MSG_BUF_SIZE 32768
AnsiString codeErreur = "";
AnsiString x = edtAncienmdp->Text;
AnsiString y = edtNouveaumdp->Text;
char* domain = "PC-STAG-03";
char* login = "test";
char* vieumdp = x.c_str();
char* newmdp = y.c_str();
char *argv[20];
argv[1] = domain;
argv[2] = login;
argv[3] = vieumdp;
argv[4] = newmdp;
WCHAR domainname[DNLEN+1]; // buffer for the domain or workstation name
WCHAR username[UNLEN+1]; // buffer for the user name
WCHAR oldpassword[PWLEN+1]; // buffer for the old password
WCHAR newpassword[PWLEN+1]; // buffer for the new password
CHAR *msgBuf; // buffer for message text from system
int msgOutPut; // buffer to capture the result of
// FormatMessage for
// future use
// determine whether the number of parameters is correct
// if not then display the proper syntax
MultiByteToWideChar(
CP_ACP, // code page
0, // character-type options
argv[1], // address of string to map
strlen(argv[1])+1, // number of characters in string inc null!!
(LPWSTR)&domainname, // address of wide-character buffer
sizeof(domainname) // size of buffer
);
MultiByteToWideChar(
CP_ACP, // code page
0, // character-type options
argv[2], // address of string to map
strlen(argv[2])+1, // number of characters in string inc null!!
(LPWSTR)&username, // address of wide-character buffer
sizeof(username) // size of buffer
);
MultiByteToWideChar(
CP_ACP, // code page
0, // character-type options
argv[3], // address of string to map
strlen(argv[3])+1, // number of characters in string inc null!!
(LPWSTR)&oldpassword, // address of wide-character buffer
sizeof(oldpassword) // size of buffer
);
MultiByteToWideChar(
CP_ACP, // code page
0, // character-type options
argv[4], // address of string to map
strlen(argv[4])+1, // number of characters in string inc null!!
(LPWSTR)&newpassword, // address of wide-character buffer
sizeof(newpassword) // size of buffer
);
codeErreur = NetUserChangePassword(
domainname, // pointer to server or domain name string
username, // pointer to user name string
oldpassword, // pointer to old password string
newpassword // pointer to new password string
);
}
Partager