You should specify where the code fails. So assign the return value of
NetUserGetInfo()
to a variable and print that upon failure like in the example code from the MSDN page for the
NetUserGetInfo function (Windows)[
^] which seems to be the source of your code.
If you got an error code of 0x8AD / 2221: That is
NERR_UserNotFound
.
I have looked up your profile and saw that you are from China. When not using an English Windows version, you must pass the guest user name for your localised Windows version.
There seems also to be a wrong condition checking in your code. You are printing "Guest is disabled" when the flag
UF_ACCOUNTDISABLE
is not set.
So you might try something like this to check it (note that the user name in the below code is "gast" which is the German guest account name and therefore works on my system):
LPUSER_INFO_1 puiVal = NULL;
NET_API_STATUS status = NetUserGetInfo(NULL, L"gast", 1, (LPBYTE*)&puiVal);
if (NERR_Success == status)
{
wprintf(L"Disabled: %d\n", (puiVal->usri1_flags & UF_ACCOUNTDISABLE) ? 1 : 0);
wprintf(L"Priv Guest: %d\n", (puiVal->usri1_flags & USER_PRIV_GUEST) ? 1 : 0);
}
else
{
wprintf(L"Failed with code %#X / %d\n", status, status);
}
if (puiVal)
NetApiBufferFree(puiVal);