Problem declaring typedef TOKEN_ELEVATION using windows api

Hello, i am trying to create one program to check if its running with admin rights or not and show a message at the user showing how he is running this application.

But i receive the follow error:
main.cpp|12|error: 'TOKEN_ELEVATION' does not name a type|

Line take me error:
typedef Elevation TOKEN_ELEVATION;

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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 ) ) {
        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;
}
Last edited on
You can use typedef to give existing types a new name like typedef unsigned char uchar
However your Elevation is not a type but the name of a variable
1
2
DWORD Elevation;
typedef Elevation TOKEN_ELEVATION;
Show me the same error:
||=== 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)) ===|
TOKEN_ELEVATION is a type. See:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb530717(v=vs.85).aspx

Hence the type of Elevation shouldn't be DWORD but TOKEN_ELEVATION.

If there is a problem with TOKEN_ELEVATION see:

http://stackoverflow.com/questions/11234763/token-elevation-type-was-not-declared-in-this-scope-what-im-doing-wrong#11234799
Topic archived. No new replies allowed.