1

我至少想区分我的软件作为批处理作业(LOGON32_LOGON_BATCH)运行和交互运行(LOGON32_LOGON_INTERACTIVE)的情况。

4

1 回答 1

2
HANDLE hToken;
// Open the current process's token
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
    // Get the token statistics, which include the logon session id
    TOKEN_STATISTICS stats;
    DWORD length;
    if (GetTokenInformation(hToken, TokenStatistics, &stats, sizeof(stats), &length))
    {
        // Get data about the logon session, which includes the logon type
        PSECURITY_LOGON_SESSION_DATA pData;
        if (LsaGetLogonSessionData(&stats.AuthenticationId, &pData) == 0)
        {
            // From SECURITY_LOGON_TYPE enumeration
            switch (pData->LogonType)
            {
            case Interactive:
                wprintf(L"Interactive\n");
                break;
            case Batch:
                wprintf(L"Batch\n");
                break;
            default:
                wprintf(L"Other: %i\n", pData->LogonType);
                break;
            }
            LsaFreeReturnBuffer(pData);
        }
    }
    CloseHandle(hToken);
}
于 2012-10-27T19:14:23.787 回答