Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Active Directory
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Active Directory
Divers
Thread ID:
00931693
Message ID:
00931693
Vues:
67
I've been succesfull in reading from the Active Directory on the server (users, groups and machines).
However, I am unable to call the NetGroupGetUsers API; the api returns with NERR_GroupNotFound. I am sure the group exists.
Here's some code I use:
DECLARE INTEGER NetGroupGetUsers IN Netapi32;
	STRING	@ servername,;
	STRING	@ groupname,;
	INTEGER	  level,;
	INTEGER	@ bufptr,;
	INTEGER	  prefmaxlen,;
	INTEGER	@ entriesread,;
	INTEGER	@ totalentries,;
	INTEGER	@ ResumeHandle

DisplayUsersInGroup( "\\Server01", "Global_groupname" )
PROCEDURE DisplayUsersInGroup
LPARAMETERS cServerName AS STRING, cGroupName AS STRING
	cBuffer2 = REPLICATE( CHR( 0 ), 254 )
	pEntriesRead = 0
	pTotalEntries = 0
	nResumeHandle = 0
	nEntriesRead = 0
	nTotalEntries = 0
	nBuf = 0

	nRet = NetGroupGetUsers(;
		  @cServerName;
		, @cGroupName;
		, 0; && Get Global Groups
		, @nBuf;
		, MAX_PREFERRED_LENGTH;
		, @pEntriesRead;
		, @pTotalEntries;
		, @nResumeHandle;
	)
	
	IF nRet = ERROR_SUCCESS OR nRet = ERROR_MORE_DATA
		* Don't know if this works, because I never get here
		=CopyMemory( @cBuffer2, pEntriesRead, 4 )
		?cBuf
		nIndex = nReturnedEntryCount
		nReturnCode = -1
	ELSE
		show_error( nRet )
	ENDIF
	
	=NetApiBufferFree( @nBuf)
ENDPROC

FUNCTION show_error
LPARAMETERS nError
	LOCAL cBuffer, nBytes
	cBuffer = REPLICATE( CHR( 0 ), 254 )
	IF PCOUNT() = 1 AND VARTYPE( nError ) == "N"
		nBytes = FormatMessage( BITOR( FORMAT_MESSAGE_FROM_SYSTEM, 0 ), -1, nError, -1, @cBuffer, 254, -1 )
		?LEFT( cBuffer, nBytes - 2 ) + TEXTMERGE( " Error Number: <<nError>>" )
	ENDIF

	cBuffer = REPLICATE( CHR( 0 ), 254 )
	nError = GetLastError()
	nBytes = FormatMessage( BITOR( FORMAT_MESSAGE_FROM_SYSTEM, 0 ), -1, nError, -1, @cBuffer, 254, -1 )
	?STRTRAN( LEFT( cBuffer, nBytes - 2 ), CHR( 0 ), "" ) + TEXTMERGE( " Error Number: <<nError>>" )
	WAIT "An error occured..." WINDOW TIMEOUT 1
ENDFUNC
Who can help?

[edit]
Well, it seems it does work. I've had to try a few times in a row, but it does work :)
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform