Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Error Code 1312 for the below code so How to fix the Win32 API function error: 1312 (GetTokenInformation) occurring for the below code used for creating a windows installer application. #363

Open
prmjh4 opened this issue Sep 10, 2024 · 0 comments

Comments

@prmjh4
Copy link

prmjh4 commented Sep 10, 2024

I have used the below code and it is working fine for most of the cases while using the windows installer but for one windows machine it is failing at the section where we call 'GetTokenInformation' win32 API function and throws an error as ERROR: API = GetTokenInformation, error code = 1312, message = A specified logon session does not exist. It may already have been terminated.)
What could have gone wrong and how can we resolve this. Please help. Thanks!

`// Logging on as the passed ssh user (not logged in user) which is non-Administrator
if (!LogonUser(username.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken)) {
DisplayError(L"LogonUser");
goto Cleanup;
}

    tokenUsed = hToken;
    
    // If the ssh user (not logged in user) is non-Administrator, we need linked token
    if (!adminUser)
    {
            if (!GetTokenInformation(hToken, TokenLinkedToken, &linkedToken, sizeof(TOKEN_LINKED_TOKEN), &returnLength))
            {
                    DisplayError(L"GetTokenInformation");
                    goto Cleanup;
            }

            // Duplicate the token to ensure valid usage
            if (!DuplicateTokenEx(linkedToken.LinkedToken, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &hDupToken)) {
                    DisplayError(L"DuplicateTokenEx");
                    goto Cleanup;
            }

            tokenUsed = hDupToken;  // Use the duplicated token
    }`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant