Я пытаюсь выяснить, почему функция LoadUserProfileW не работает. Вот коды ошибок, которые я вижу:
E_ACCESSDENIED (29 times)
0x80070020 (6 times)
Точный общедоступный исходный код, в котором время от времени происходит сбой.
Мне интересно, в чем может быть основная причина, потому что, как вы можете видеть в LoadUserProfileW
code> в случае сбоя либо CreateUserTokenWithSid, либо LogonUser завершились успешно. Итак, судя по кодам ошибок, что препятствует загрузке профиля загрузки (он же C:\Users\).
Я ценю любую помощь/подсказку. Спасибо.
Открытый исходный код исходных ошибок, которые я изучаю:
wstring const & accountName,
wstring const & domain,
wstring const & password,
DWORD logonType,
DWORD logonProvider,
bool loadProfile,
PSID const & sid,
__out TokenHandleSPtr & tokenHandle,
__out ProfileHandleSPtr & profileHandle) {
ASSERT_IF(accountName.empty(), "AccountName must not be empty.");
ASSERT_IF(password.empty(), "Password must not be empty.");
HANDLE token;
if (sid)
{
auto error = AccessToken::CreateUserTokenWithSid(accountName, domain, password, logonType, logonProvider, sid, tokenHandle);
if (!error.IsSuccess())
{
return error;
}
}
else
{
if (!::LogonUser(accountName.c_str(), domain.c_str(), password.c_str(), logonType, logonProvider, &token))
{
auto error = ErrorCode::FromWin32Error();
TraceWarning(
TraceTaskCodes::Common,
TraceType_AccessToken,
"LogonUser failed for {0}. ErrorCode={1}",
accountName,
error);
return error;
}
tokenHandle = TokenHandle::CreateSPtr(token);
}
if (loadProfile)
{
PROFILEINFO profileInfo = { 0 };
profileInfo.dwSize = sizeof(profileInfo);
profileInfo.lpUserName = (LPWSTR)&accountName[0];
if (!::LoadUserProfileW(tokenHandle->Value, &profileInfo))
{
auto error = ErrorCode::FromWin32Error();
TraceWarning(
TraceTaskCodes::Common,
TraceType_AccessToken,
"LoadUserProfileW failed for {0}. ErrorCode={1}",
accountName,
error);
return error;
}
profileHandle = ProfileHandle::CreateSPtr(tokenHandle, profileInfo.hProfile);
TraceInfo(
TraceTaskCodes::Common,
TraceType_AccessToken,
"LoadUserProfileW succeeded for {0}.",
accountName);
}
return ErrorCode(ErrorCodeValue::Success); } ```cpp ErrorCode AccessToken::GetUserTokenAndProfileHandle(
Минимальный воспроизводимый пример LoadUserProfileW
Repo
#include
#include
#include
#include
#include
using namespace std;
#pragma comment(lib, "userenv.lib")
NET_API_STATUS CreateUserAccount(wstring const & accountName, wstring const & password)
{
USER_INFO_4 userInfo;
::ZeroMemory(&userInfo, sizeof(userInfo));
userInfo.usri4_name = const_cast(accountName.c_str());
userInfo.usri4_password = const_cast(password.c_str());
userInfo.usri4_flags = UF_SCRIPT | UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD | UF_NOT_DELEGATED | UF_NORMAL_ACCOUNT;
userInfo.usri4_acct_expires = TIMEQ_FOREVER;
userInfo.usri4_primary_group_id = DOMAIN_GROUP_RID_USERS;
const NET_API_STATUS nStatus = ::NetUserAdd(nullptr, 4 /* USER_INFO level*/, reinterpret_cast(&userInfo), nullptr);
return nStatus;
}
std::wstring NetApiStatusToString(NET_API_STATUS status)
{
wchar_t* messageBuffer = nullptr;
DWORD result = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, status, 0, reinterpret_cast(&messageBuffer), 0, nullptr);
std::wstring message;
if (result != 0 && messageBuffer != nullptr) {
message = messageBuffer;
message.erase(message.find_last_not_of(L"\r\n") + 1);
LocalFree(messageBuffer);
} else {
message = L"Unknown error code";
}
return message;
}
int main() {
NET_API_STATUS createAccountResult = CreateUserAccount(L"taha", L"passqZ@@w-S9:d80");
const wstring createAccountResultMessage = NetApiStatusToString(createAccountResult);
wcout
Подробнее здесь: https://stackoverflow.com/questions/793 ... 0x80070020
Ошибка `LoadUserProfileW` с кодами ошибок E_ACCESSDENIED / 0x80070020 ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
`LoadUserProfileW` не работает с кодами ошибок, где найти список кодов ошибок [дубликат]
Anonymous » » в форуме C++ - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-