FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Detect if the current user is Administrator
Posts: 208
Joined: Wed Dec 03, 2008 04:48 PM
Detect if the current user is Administrator
Posted: Thu Aug 23, 2012 04:19 PM

Before start some function in my programs, sometimes I would like to know if the current user is ADMINISTRATOR or belongs to ADMINISTRATORS
Is there any way to accomplish this?
Because then, if the user is not an ADMINISTARTOR, I would deny to allow him to run some part of the program

Thanks

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Detect if the current user is Administrator
Posted: Thu Aug 23, 2012 06:20 PM

Maybe You are using a LOGIN ?

I added a Permission-level to the LOGIN ( encrypted )

like : Login_1 ( 1 to _5 is the level )
from the encrypted Login I save the
? Level to a global Var.

  1. Administrator
  2. can write and delete
  3. can only read
  4. cannot load Function 1
  5. cannot load Function 2

Next I call the Function related to the Level like :
IF LEVEL > 4 ( low Level )
MsgAlert( "No Permission for this Action","LOCKED" )
ELSE
MY_FUNCTION()
ENDIF

Best Regards
Uwe :lol:

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: Detect if the current user is Administrator
Posted: Thu Aug 23, 2012 08:22 PM

You can run the command "whoami /groups" and treat the result to find out if the user belongs to the group you are looking for. If your are using XP you can do the same with "net user %USERNAME%".

Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Detect if the current user is Administrator
Posted: Fri Aug 24, 2012 04:13 AM
Please try this code
Code (fw): Select all Collapse
#include "FiveWin.ch"
//------------------//
FUNCTION Main()
    MsgInfo( IsUserAnAdmin() ) // Returns either .T. or .F.
Return   
DLL32 STATIC FUNCTION IsUserAnAdmin() AS BOOL PASCAL LIB "Shell32.dll"


Regards
Anser
Posts: 208
Joined: Wed Dec 03, 2008 04:48 PM
Re: Detect if the current user is Administrator
Posted: Sun Aug 26, 2012 07:46 AM

Thanks,

I am using "anselkk" suggestion and it works for me.

Continue the discussion