hi,
how can i identify when App was start as Administrator ?
greeting,
Jimmy
Jimmy
hi,
how can i identify when App was start as Administrator ?
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 nilProper 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
hi Antonio,
THX for the Solutions.