how to identify when App was start as Aministator ?
Posted: Thu May 07, 2026 6:36 pm
hi,
how can i identify when App was start as Administrator ?
how can i identify when App was start as Administrator ?
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://mail.hmgforum.com/
//=============================================================================
Code: Select all
#include <hmg.ch>
PROCEDURE MAIN
PRIVATE lIsAdmin := wapi_IsUserAnAdmin()
IF .Not. lIsAdmin .AND. MsgYesNo ( "The application does not run in administrator mode, do you want to run it as an administrator?", "Run As Administrator" )
RunApiAsAdministrator()
RETURN
ENDIF
Msgdebug ( "Does the application run in administrator mode?" , lIsAdmin )
/* rest of prg */
RETURN
Function RunApiAsAdministrator()
ShellExecuteEx( wapi_GetActiveWindow(), 'runas', hb_ProgName(), , , SW_SHOWNORMAL )
Return Nil
#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include <hbapi.h>
#include <shlobj.h>
HB_FUNC( SHELLEXECUTEEX )
{
SHELLEXECUTEINFO SHExecInfo;
ZeroMemory(&SHExecInfo, sizeof(SHExecInfo));
SHExecInfo.cbSize = sizeof(SHExecInfo);
SHExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
SHExecInfo.hwnd = HB_ISNIL( 1 ) ? GetActiveWindow() : (HWND) HMG_parnl( 1 );
SHExecInfo.lpVerb = (LPCSTR) HMG_parc( 2 );
SHExecInfo.lpFile = (LPCSTR) HMG_parc( 3 );
SHExecInfo.lpParameters = (LPCSTR) HMG_parc( 4 );
SHExecInfo.lpDirectory = (LPCSTR) HMG_parc( 5 );
SHExecInfo.nShow = hb_parni( 6 );
if( ShellExecuteEx(&SHExecInfo) )
{
// hb_retnl( (LONG) SHExecInfo.hProcess );
CloseHandle(SHExecInfo.hProcess);
}
}
#pragma ENDDUMP