microsoft / microsoft/Windows-classic-samples
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.
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 5.7k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
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
}`
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the LogonUser, GetTokenInformation, and DuplicateTokenEx calls in the issue's code path. Reproduce the failure on the affected Windows machine and compare its logon session and token context with a working machine. Done means identifying the cause of error 1312 and documenting a verified resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100