if (!LogonUser(pLogonInfo->szUsr, pLogonInfo->szDom, pLogonInfo->szPass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &htoken)) { vd_printf("LogonUser failed %d, user: %S, domain: %S", GetLastError(), pLogonInfo->szUsr, pLogonInfo->szDom); return false; } memset(&cuProfileInfo, 0, sizeof(cuProfileInfo)); cuProfileInfo.dwSize = sizeof(PROFILEINFO); cuProfileInfo.lpUserName = pLogonInfo->szUsr; cuProfileInfo.dwFlags = 1; ret = LoadUserProfile(htoken, &cuProfileInfo); if (ERROR_INVALID_PARAMETER == ret || 0 == ret) { printf("LoadUserProfile failed %d", GetLastError()); CloseHandle(htoken); return false; } status = RegOpenKeyEx((struct HKEY__ *)cuProfileInfo.hProfile, reg_key, 0, KEY_SET_VALUE|KEY_QUERY_VALUE, &hKey); if (ERROR_SUCCESS != status) { status = RegCreateKeyEx((struct HKEY__ *)cuProfileInfo.hProfile, reg_key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if (ERROR_SUCCESS != status) { printf("Find registerkey Software\\VDAgent\\LogonInfo failed"); UnloadUserProfile(htoken, cuProfileInfo.hProfile); CloseHandle(htoken); return false; } }