判断某个程序是不是管理员运行的
-
返回值 大于$3000就是管理员权限
function GetIntegrityLevel(const Pid: Cardinal) : DWORD; var hProcess, hToken : THandle; cbSize: DWORD; pTIL : PSIDAndAttributes; dwTokenUserLength: DWORD; begin Result := 0; dwTokenUserLength := MAXCHAR; hProcess := OpenProcess(PROCESS_QUERY_INFORMATION, False, Pid); if hProcess = 0 then Exit; if OpenProcessToken(hProcess, TOKEN_QUERY, hToken) then begin pTIL := Pointer(LocalAlloc(0, dwTokenUserLength)); if pTIL = nil then Exit; cbSize := SizeOf(TSIDAndAttributes); if GetTokenInformation(hToken, TokenIntegrityLevel, pTIL, dwTokenUserLength, cbSize) then if IsValidSid( pTIL.Sid ) then Result := GetSidSubAuthority(pTIL.Sid, GetSidSubAuthorityCount(pTIL.Sid)^ - 1)^; if hToken <> INVALID_HANDLE_VALUE then CloseHandle(hToken); LocalFree(Cardinal(pTIL)); end; CloseHandle(hProcess); end;