Código:
||=== Build: Debug in main (compiler: GNU GCC Compiler) ===|
C:\Users\Androide\Desktop\main.cpp||In function 'BOOL IsElevated()':|
C:\Users\Androide\Desktop\main.cpp|13|error: 'Elevation' does not name a type|
C:\Users\Androide\Desktop\main.cpp|14|error: 'TOKEN_ELEVATION' was not declared in this scope|
C:\Users\Androide\Desktop\main.cpp|15|error: 'TokenElevation' was not declared in this scope|
C:\Users\Androide\Desktop\main.cpp|16|error: request for member 'TokenIsElevated' in 'Elevation', which is of non-class type 'DWORD {aka long unsigned int}'|
C:\Users\Androide\Desktop\main.cpp|10|warning: unused variable 'Elevation' [-Wunused-variable]|
||=== Build failed: 4 error(s), 1 warning(s) (0 minute(s), 2 second(s)) ===|
Código:
#include <iostream>
#include <windows.h>
#include <winnt.h>
using namespace std;
BOOL IsElevated( ) {
BOOL fRet = FALSE;
HANDLE hToken = NULL;
DWORD Elevation;
if( OpenProcessToken( GetCurrentProcess( ),TOKEN_QUERY,&hToken ) ) {
DWORD Elevation;
typedef Elevation TOKEN_ELEVATION;
DWORD cbSize = sizeof( TOKEN_ELEVATION );
if( GetTokenInformation( hToken, TokenElevation, &Elevation, sizeof( Elevation ), &cbSize ) ) {
fRet = Elevation.TokenIsElevated;
}
}
if( hToken ) {
CloseHandle( hToken );
}
return fRet;
}
int main()
{
bool valor=IsElevated( );
if(valor==true){
cout << "Tienes permisos de administrador";
}else{
cout << "Eres un usuario corriente";
}
system("pause");
return 0;
}