1 DWORD GetIntegrityLevel() 2 { 3 DWORD Result = 0; 4 if(!IsVista()) return Result; 5 HANDLE hToken; 6 HANDLE hProcess; 7 DWORD dwLengthNeeded; 8 DWORD dwError = ERROR_SUCCESS; 9 PTOKEN_MANDATORY_LABEL pTIL = NULL; 10 DWORD dwIntegrityLevel;11 hProcess = GetCurrentProcess(); 12 if (OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_QUERY_SOURCE, &hToken)) 13 { 14 if (!GetTokenInformation(hToken, (::TOKEN_INFORMATION_CLASS)TokenIntegrityLevel, NULL, 0, &dwLengthNeeded)) 15 { 16 dwError = GetLastError(); 17 if (dwError == ERROR_INSUFFICIENT_BUFFER) 18 { 19 pTIL = (PTOKEN_MANDATORY_LABEL)LocalAlloc(0, dwLengthNeeded); 20 if (pTIL != NULL) 21 { 22 if (GetTokenInformation(hToken, (::TOKEN_INFORMATION_CLASS)TokenIntegrityLevel, pTIL, dwLengthNeeded, &dwLengthNeeded)) 23 { 24 dwIntegrityLevel = *GetSidSubAuthority(pTIL->Label.Sid, 25 (DWORD)(UCHAR)(*GetSidSubAuthorityCount(pTIL->Label.Sid)-1));26 if (dwIntegrityLevel < SECURITY_MANDATORY_MEDIUM_RID) 27 { 28 Result = IL_LOW; 29 MessageBox(0,"low","low",MB_OK);30 } 31 else if (dwIntegrityLevel >= SECURITY_MANDATORY_MEDIUM_RID && 32 dwIntegrityLevel < SECURITY_MANDATORY_HIGH_RID) 33 { 34 Result = IL_MEDIUM; 35 MessageBox(0,"MEDIUM","MEDIUM",MB_OK);36 } 37 else if (dwIntegrityLevel >= SECURITY_MANDATORY_HIGH_RID) 38 { 39 Result = IL_HIGH; 40 MessageBox(0,"HIGH","HIGH",MB_OK);41 } 42 }43 LocalFree(pTIL); 44 } 45 } 46 } 47 CloseHandle(hToken); 48 }49 return Result; 50 }