From 7e23d873dc9efc48318c2d4137024bd7f2dc5a62 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 27 Nov 2022 21:48:20 +0100 Subject: [PATCH] Check elevation status on Windows. --- profiler/build/win32/Tracy.vcxproj | 2 ++ profiler/build/win32/Tracy.vcxproj.filters | 6 ++++ profiler/src/IsElevated.cpp | 32 ++++++++++++++++++++++ profiler/src/IsElevated.hpp | 6 ++++ 4 files changed, 46 insertions(+) create mode 100644 profiler/src/IsElevated.cpp create mode 100644 profiler/src/IsElevated.hpp diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 834e38c5..83351c3d 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -212,6 +212,7 @@ + @@ -347,6 +348,7 @@ + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index a97ea0b0..31415380 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -378,6 +378,9 @@ server + + src + @@ -764,6 +767,9 @@ server + + src + diff --git a/profiler/src/IsElevated.cpp b/profiler/src/IsElevated.cpp new file mode 100644 index 00000000..2f257b72 --- /dev/null +++ b/profiler/src/IsElevated.cpp @@ -0,0 +1,32 @@ +#include "IsElevated.hpp" + +#ifdef _WIN32 + +#include + +bool IsElevated() +{ + HANDLE token; + if( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ) == 0 ) return false; + + TOKEN_ELEVATION te; + DWORD sz; + if( GetTokenInformation( token, TokenElevation, &te, sizeof( te ), &sz ) == 0 ) + { + CloseHandle( token ); + return false; + } + + bool ret = te.TokenIsElevated; + CloseHandle( token ); + return ret; +} + +#else + +bool IsElevated() +{ + return false; +} + +#endif diff --git a/profiler/src/IsElevated.hpp b/profiler/src/IsElevated.hpp new file mode 100644 index 00000000..35c73984 --- /dev/null +++ b/profiler/src/IsElevated.hpp @@ -0,0 +1,6 @@ +#ifndef __ISELEVATED_HPP__ +#define __ISELEVATED_HPP__ + +bool IsElevated(); + +#endif