mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-11-04 14:20:06 +00:00 
			
		
		
		
	Added basic high privilege checks and message box
This commit is contained in:
		
							parent
							
								
									d81f187d88
								
							
						
					
					
						commit
						71f967d536
					
				
					 4 changed files with 75 additions and 2 deletions
				
			
		
							
								
								
									
										43
									
								
								scwx-qt/source/scwx/qt/util/check_privilege.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								scwx-qt/source/scwx/qt/util/check_privilege.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,43 @@
 | 
			
		|||
#include "scwx/qt/util/check_privilege.hpp"
 | 
			
		||||
#include <QtGlobal>
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace scwx {
 | 
			
		||||
namespace qt {
 | 
			
		||||
namespace util {
 | 
			
		||||
 | 
			
		||||
bool is_high_privilege()
 | 
			
		||||
{
 | 
			
		||||
#if defined(_WIN32)
 | 
			
		||||
   bool   isAdmin = false;
 | 
			
		||||
   HANDLE token    = NULL;
 | 
			
		||||
   TOKEN_ELEVATION elevation;
 | 
			
		||||
   DWORD           elevationSize = sizeof(TOKEN_ELEVATION);
 | 
			
		||||
 | 
			
		||||
   if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
 | 
			
		||||
   {
 | 
			
		||||
      return false;
 | 
			
		||||
   }
 | 
			
		||||
   if (!GetTokenInformation(
 | 
			
		||||
          token, TokenElevation, &elevation, elevationSize, &elevationSize))
 | 
			
		||||
   {
 | 
			
		||||
      CloseHandle(token);
 | 
			
		||||
      return false;
 | 
			
		||||
   }
 | 
			
		||||
   isAdmin = elevation.TokenIsElevated;
 | 
			
		||||
   CloseHandle(token);
 | 
			
		||||
   return isAdmin;
 | 
			
		||||
#elif defined(Q_OS_UNIX)
 | 
			
		||||
   // On UNIX root is always uid 0. On Linux this is enforced by the kernal.
 | 
			
		||||
   return geteuid() == 0;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace util
 | 
			
		||||
} // namespace qt
 | 
			
		||||
} // namespace scwx
 | 
			
		||||
							
								
								
									
										11
									
								
								scwx-qt/source/scwx/qt/util/check_privilege.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								scwx-qt/source/scwx/qt/util/check_privilege.hpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
 | 
			
		||||
namespace scwx {
 | 
			
		||||
namespace qt {
 | 
			
		||||
namespace util {
 | 
			
		||||
 | 
			
		||||
bool is_high_privilege();
 | 
			
		||||
 | 
			
		||||
} // namespace util
 | 
			
		||||
} // namespace qt
 | 
			
		||||
} // namespace scwx
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue