Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

about NetUserSetInfo

17 views
Skip to first unread message

zds

unread,
Feb 10, 2009, 9:45:00 PM2/10/09
to
I use NetUserSetInfo() function to change administrator's password.

the code is below:

USER_INFO_1003 pi1003;
NET_API_STATUS nas;
LPCWSTR username = L"Administrator";

// random password
int i = 0;
char ch, str[7];
srand((int)time(0));
while(1)
{
ch = 1+(int)(200.0*rand()/(RAND_MAX+1.0));
if(isalnum(ch))
{
str[i++] = ch;
if(i == 6)
break;
}
}
str[6] = '\0';
printf("password is %s\n",str);


pi1003.usri1003_password = (WCHAR *)_T (str);

nas = NetUserSetInfo(
NULL, // computer name
username, // username
1003, // info level
(LPBYTE)&pi1003, // new info
NULL
);
if(nas != NERR_Success)
{
if(nas == NERR_UserNotFound)
{
printf("User Not Found!\n");
}
printf("ERROR!\n");
return 1;
}

printf("success!\n");

but it does not work, why ,thanks!

Onega

unread,
Feb 14, 2009, 10:25:21 PM2/14/09
to zds

If you don't mind using ADSI, here is an example.
http://support.microsoft.com/kb/255042
How to make machine accounts programmatically by using ADSI with Visual C++

0 new messages