Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine that the User has Admin privileges
Message
 
 
To
29/08/2003 04:42:16
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00824487
Message ID:
00824727
Views:
33
Try
#define USER_PRIV_GUEST     0
#define USER_PRIV_USER      1
#define USER_PRIV_ADMIN     2
DECLARE Long NetUserGetInfo IN Netapi32.dll ;
  	String servername, String username, ;
    Long level, String @ bufptr
DECLARE Long NetApiBufferFree IN Netapi32.dll String @ Buffer
lcBufPtr = REPLICATE(CHR(0), 4)
* Convert user name to Unicode
lcUserName = STRCONV("MyUserName",5)
lnLevel = 1
IF NetUserGetInfo(0, lcUserName, lnLevel, @lcBufPtr) <> 0
	* Error
	RETURN .F.
ENDIF
* Retrieve USER_INFO_1 buffer into string
lcBuffer = SYS(2600, Long2Num(lcBufPtr), 32)
* Check priviliges
IF BITAND(ASC(SUBSTR(lcBuffer, 13, 1)), USER_PRIV_ADMIN) > 0 
	? "Administrator"
ENDIF	
* Free buffer
= NetApiBufferFree(@lcBufPtr)
RETURN
*---------------------------------
FUNCTION Long2Num(tcLong)
DECLARE RtlMoveMemory IN WIN32API Long @Dest, ;
		String @Source, Long Length
LOCAL lnNum
lnNum = 0
= RtlMoveMemory(@lnNum, tcLong, 4)
RETURN lnNum
>I want to find out if the currently logged User has Admin privileges. Using NetUserGetInfo() this can be done but I am not able to pass proper parameters and get the return value. NetUserGetInfo() returns error 123 or 2221. Please help or pass me a code snippet which works.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform