Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
User Privileges
Message
De
01/07/2002 10:07:20
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Divers
Thread ID:
00672393
Message ID:
00673847
Vues:
10
>Is there a API call to find the Group Membership (Standard/Restricted/Other... ) of the current user for Win2000.
>
>I am having a problem with installing a FaxDriver and PDF drivers because the users has only Restricted rights and can not install printers.
>
>Thanks in advance.
>
>jim durkin

You can use sys(0) function to retrieve current user name. To check for group membership of this user you should know the domain name. You can utilize the NETAPI functions.
See the example bellow:
Declare long NetUserGetInfo In netapi32 ;
  String @ servername, ;
  String @ username, ;
  Long level, ;
  long @ bufptr

Declare long NetUserGetGroups In netapi32 ;
	String @ servername, ;
	String @ username, ;
	Long level, ;
	Long @ bufptr, ;
	Long prefmaxlen, ;
	Long @ entriesread, ;
	Long @ totalentries

Declare long NetUserGetLocalGroups In netapi32 ;
	String @ servername, ;
	String @ username, ;
	Long level, ;
	Long flags, ;
	Long @ bufptr, ;
	Long prefmaxlen, ;
	Long @ entriesread, ;
	Long @ totalentries

Declare long NetApiBufferFree In netapi32 ;
	Long Buffer

Local lcServerName, lcUserName, lnBuffer, lnIndex, ;
	lcStrAddress, lnStrAddress, lcUserName, ;
	lnUGroupCount, lnGroupCount, lcUserGroup

*** Set server-computer name and user name bellow:
#DEFINE ServerName '\\JEI-Server'+Chr(0)
#DEFINE UserName 'Zlatin'+Chr(0)

lcServerName = Strconv(ServerName,5)
lcUserName = Strconv(UserName,5)
lnBuffer = 0

If !Empty(NetUserGetInfo(@lcServerName, @lcUserName, 0, @lnBuffer))
	?'User not found!'
	Return .f.
EndIF

lcStrAddress = SYS(2600, lnBuffer, 4)
lnStrAddress = asc(left(lcStrAddress, 1)) + ;
	asc(substr(lcStrAddress, 2, 1)) * 256 + ;
	asc(substr(lcStrAddress, 3, 1)) * 65536 + ;
	asc(substr(lcStrAddress, 4, 1)) * 16777216

lcUserName = SYS(2600, lnStrAddress, 256)
lcUserName = Strconv(lcUserName,6)
lcUserName = Left(lcUserName, At(Chr(0), lcUserName)-1)
?chr(13)+Chr(10)+lcUserName
=NetAPIBufferFree(lnBuffer)

lcServerName = Strconv(ServerName,5)
lcUserName = Strconv(UserName,5)
lnBuffer = 0
lnUGroupCount = 0
lnGroupCount = 0
??' is member of the following '
NetUserGetGroups(@lcServerName, @lcUserName, 0, @lnBuffer, 255, @lnUGroupCount, @lnGroupCount)
??Transform(lnUGroupCount) + [ groups: ]+chr(13)+Chr(10)
lcStrAddress = SYS(2600, lnBuffer, 4*lnUGroupCount)
For lnIndex = 1 To lnUGroupCount
	lnStrAddress = asc(substr(lcStrAddress, 1+(lnIndex-1)*4, 1)) + ;
		asc(substr(lcStrAddress, 2+(lnIndex-1)*4, 1)) * 256 + ;
		asc(substr(lcStrAddress, 3+(lnIndex-1)*4, 1)) * 65536 + ;
		asc(substr(lcStrAddress, 4+(lnIndex-1)*4, 1)) * 16777216
	lcUserGroup = SYS(2600, lnStrAddress, 256)
	lcUserGroup = Strconv(lcUserGroup,6)
	lcUserGroup = Left(lcUserGroup, At(Chr(0), lcUserGroup)-1)
	?lcUserGroup
Endfor

=NetAPIBufferFree(lnBuffer)

lcServerName = Strconv(ServerName,5)
lcUserName = Strconv(UserName,5)
lnBuffer = 0
lnUGroupCount = 0
lnGroupCount = 0
?chr(13)+Chr(10)+'and is member of the following '
NetUserGetLocalGroups(@lcServerName, @lcUserName, 0, 1, @lnBuffer, 255, @lnUGroupCount, @lnGroupCount)
??Transform(lnUGroupCount) + [ local groups: ]+chr(13)+Chr(10)
lcStrAddress = SYS(2600, lnBuffer, 4*lnUGroupCount)
For lnIndex = 1 To lnUGroupCount
	lnStrAddress = asc(substr(lcStrAddress, 1+(lnIndex-1)*4, 1)) + ;
		asc(substr(lcStrAddress, 2+(lnIndex-1)*4, 1)) * 256 + ;
		asc(substr(lcStrAddress, 3+(lnIndex-1)*4, 1)) * 65536 + ;
		asc(substr(lcStrAddress, 4+(lnIndex-1)*4, 1)) * 16777216
	lcUserGroup = SYS(2600, lnStrAddress, 256)
	lcUserGroup = Strconv(lcUserGroup,6)
	lcUserGroup = Left(lcUserGroup, At(Chr(0), lcUserGroup)-1)
	?lcUserGroup
Endfor

=NetAPIBufferFree(lnBuffer)
?chr(13)+Chr(10)
HTH
Zlatin Zlatev,
MCSD (VS6)

Make solutions, not programs!

Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform