FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour how to identify when App was start as Administrator ?
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
how to identify when App was start as Administrator ?
Posted: Thu May 07, 2026 06:37 PM

hi,

how can i identify when App was start as Administrator ?

greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to identify when App was start as Administrator ?
Posted: Thu May 07, 2026 06:40 PM

Dear Jimmy,

Not in FWH yet (included for next build). Two distinct things:

  • Is admin = user belongs to Administrators group

  • Is elevated = process token currently has admin rights (UAC split token)

    Most apps want elevated. Cleanest: GetTokenInformation with TokenElevation (Vista+).

    Quick PRG check using shell32.IsUserAnAdmin (deprecated but works XP→Win11):

  DLL32 FUNCTION IsUserAnAdmin() AS BOOL PASCAL FROM "IsUserAnAdmin" LIB "shell32.dll"

  function Main()
     if IsUserAnAdmin()
        MsgInfo( "Running elevated" )
     else
        MsgInfo( "Not elevated" )
     endif
  return nil

Proper way (TokenElevation, Vista+, no deprecation): C helper.

  #include <hbapi.h>
  #include <windows.h>

  HB_FUNC( ISELEVATED )
  {
     HANDLE hToken = NULL;
     TOKEN_ELEVATION te;
     DWORD dwSize = 0;
     BOOL bElevated = FALSE;

 if( OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ) )
 {
    if( GetTokenInformation( hToken, TokenElevation, &te, sizeof( te ), &dwSize ) )
       bElevated = te.TokenIsElevated;
    CloseHandle( hToken );
 }
 hb_retl( bElevated );
  }

Run elevated programmatically if user clicks "run as admin" button:

ShellExecute( 0, "runas", "myapp.exe", "", "", 1 ) // UAC prompt

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to identify when App was start as Administrator ?
Posted: Fri May 08, 2026 10:12 AM

hi Antonio,

THX for the Solutions.

greeting,

Jimmy

Continue the discussion