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

NetUserSetInfo()

17 views
Skip to first unread message

zds

unread,
Feb 10, 2009, 9:42:02 PM2/10/09
to
Hello! I use NetUserSetInfo() function to set the 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");

0 new messages