IsUserAnAdminInVista

The day I started working on my project, the shell32 function – IsUserAnAdmin() (Err, MSDN link couldn’t be found Finally, MSDN people added its link) – created problems for my team. On Vista UAC ON the aforementioned function will not give correct results unless you elevate the process. This was undesirable.

Searching on net (using Google, of-course πŸ™‚ ) I found out Vista UAC tools containing various useful functions like getting the elevation type of a process, checking if a process is elevated or not, etc. After pondering over the functions and their purposes I came up with a customized function – IsUserAnAdminInVista() using the following functions:

1. HRESULT GetElevationType( __out TOKEN_ELEVATION_TYPE * ptet )

2. HRESULT IsElevated( __out_opt BOOL * pbElevated = NULL )

That said the admin status can now be found out without much hassle by doing the following:

-> If ptet != TokenElevationTypeDefault then ADMIN and UAC ON.

-> else if pbElevated == TRUE – (this means ptet value is TokenElevationTypeDefault which implies either UAC is OFF or it’s a standard user. But, since pbElevated is TRUE this means ADMIN and UAC OFF).

-> else NON-ADMIN (UAC status can’t be determined)
Was it useful? Certainly yes, the above can also be used to determine the UAC status efficiently (but only when you have admin privileges πŸ™‚ )

Cheers,

One thought on “IsUserAnAdminInVista

  1. When did u learn greek ??? I am sure the text written above is surely not in english … yeh kya hai bhai !!

Leave a comment