Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Admin or Power User in NT
Message
De
29/04/1999 08:42:50
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00213363
Message ID:
00213389
Vues:
40
>Anyone got the code to determine if a user on a NT workstation has Administrator rights or not?
>
Under NT, you can use NetUserGetInfo(); if you call it with a level of 11, it'll return a privileges mask in the returned USER_INFO_11 structure. Using some of the functions from CLSHEAP, the code would look something like the following, untested code:
DECLARE INTEGER NetUserGetInfo IN NETAPI32 ;
   STRING @ servername, ;
   STRING @ username, ;
   INTEGER level, ;
   INTEGER lpBufPtr

DECLARE INTEGER WNetGetUser IN WIN32API ;
   STRING @ lpName
   STRING @ lpBuffer
   INTEGER @ lpnLength

cName = 0
cBuff = SPACE(256)
nLen = 256
*  Get the Windows Login Name
=WNetGetUser(cName, @cBuff, @nLen)
*  Store the login name in a variable, stripping excess buffer
cUser = LEFT(cBuff,AT(CHR(0),cBuff)-1)
*  We need a couple of functions from CLSHEAP, so
SET PROCEDURE TO CLSHEAP ADDITIVE
cMyServer = 0  && null pointer selects local machine
nPtr = 0       && init so we can return something in it
IF NetGetUserInfo(cMyServer, cUser, 11, @nPtr) = 0
   *  nPtr contains a pointer to a buffer containing a USER_INFO_11
   cUSERINFO = GetMem(nPtr,80)  && the structure is 80 bytes long
   =DeAllocNetAPIBuffer(nPtr)   && release the NetAPI buffer at (nPtr)
   nPriv = DWORDToNum(SUBST(cUSERINFO,17))  && 5th DWORD is priv level 
   *  0 = Guest, 1 = User, 2 = Admin
   nAuth = DWORDToNum(SUBST(cUSERINFO,21))  && 6th DWORD is auth bitmask
   *  Print Op 1, Comm Op 2, Server Op 4, Account Op 8 
ENDIF
You might find the information in a level 2 (USER_INFO_2 structure) more useful - the user should be able to query his own account at level 11 at a minimum. You'll probably need to look at the MSDN docs on the API call and the structures; if you have an MSDN subscription, it's in the Platform SDK documentation, the constants can be found in LMACCESS.H in the INCLUDE directory of VC++. You can also access the Platform SDK docs from the MSDN online web site.

If you need details on group membership rather than privilege and authorization flags, you can use NetUserGetGroups(); you can retrieve your group membership

You can also turn to the ADSI OLE Automation object rather than the API to retrieve the data.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform