Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine that the User has Admin privileges
Message
 
 
À
02/09/2003 09:55:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00824487
Message ID:
00825698
Vues:
28
This message has been marked as a message which has helped to the initial question of the thread.
Below's the code that works for me. I didn't test it for a user that does't have admin privileges. There's a class that helps to work with structures in VFP Heap allocation class File #9482.
LPARAMETERS tcUserName
#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(tcUserName,5) + CHR(0)
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 privileges
IF BITAND(ASC(SUBSTR(lcBuffer, 13, 1)), USER_PRIV_ADMIN) > 0 
	lcResult = "Administrator"
ELSE
	lcResult = "Other"
ENDIF	
* Free buffer
= NetApiBufferFree(@lcBufPtr)
RETURN lcResult
*---------------------------------
FUNCTION Long2Num(tcLong)
DECLARE RtlMoveMemory IN WIN32API Long @Dest, ;
		String @Source, Long Length
LOCAL lnNum
lnNum = 0
= RtlMoveMemory(@lnNum, tcLong, 4)
RETURN lnNum
>It still doesnt work, gives the same error.
>Is there any way other than SYS(2600) to retrieve the contents from that buffer?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform