add admin check (and don't log it if it fails).

This commit is contained in:
Marcos Slomp
2025-12-08 08:40:26 -08:00
parent 04c32562a0
commit 86a6b9b671
2 changed files with 16 additions and 0 deletions

View File

@@ -185,6 +185,9 @@ bool SysTraceStart( int64_t& samplingPeriod )
s_pid = GetCurrentProcessId();
if ( !etw::CheckAdminPrivilege() )
return false;
session = etw::StartPrivateKernelSession( "TracySysTrace" );
if (session.handle == 0)
return false;

View File

@@ -160,6 +160,19 @@ static ULONG ETWError( ULONG result )
return result;
}
static bool CheckAdminPrivilege()
{
HANDLE hToken = NULL;
if ( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ) == FALSE )
return ETWError( GetLastError() ), false;
TOKEN_ELEVATION_TYPE elevationType = TokenElevationTypeDefault;
DWORD ReturnLength = 0;
if ( GetTokenInformation( hToken, TokenElevationType, &elevationType, sizeof( elevationType ), &ReturnLength ) == FALSE )
ETWError( GetLastError() ), false;
CloseHandle( hToken );
return ( elevationType == TokenElevationTypeFull );
}
static DWORD ElevatePrivilege( LPCTSTR PrivilegeName )
{
TOKEN_PRIVILEGES tp = {};