Detect if the current user is Administrator

Detect if the current user is Administrator

Postby codemaker » Thu Aug 23, 2012 4: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
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Detect if the current user is Administrator

Postby ukoenig » Thu Aug 23, 2012 6: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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Detect if the current user is Administrator

Postby ADutheil » Thu Aug 23, 2012 8: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
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Detect if the current user is Administrator

Postby anserkk » Fri Aug 24, 2012 4:13 am

Please try this code
Code: Select all  Expand view
#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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Detect if the current user is Administrator

Postby codemaker » Sun Aug 26, 2012 7:46 am

Thanks,

I am using "anselkk" suggestion and it works for me.
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 98 guests