/**
* Based on {@link Netapi32Util#getUsers}, but returns more information.
*/
static void enumerateUserInfo(String serverName, UserInfoRecipient recipient) {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesRead = new IntByReference();
IntByReference totalEntries = new IntByReference();
try {
int rc = Netapi32.INSTANCE.NetUserEnum(
serverName, 10, LMAccess.FILTER_NORMAL_ACCOUNT, bufptr,
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
totalEntries, null);
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
throw new Win32Exception(rc);
}
USER_INFO_10 user = new USER_INFO_10(bufptr.getValue());
USER_INFO_10[] users = (USER_INFO_10[]) user.toArray(entriesRead.getValue());
for (USER_INFO_10 lu : users) {
recipient.receiveUserInfo(lu.usri10_name.toString(), lu.usri10_full_name.toString());
}
} finally {
if (bufptr.getValue() != Pointer.NULL) {
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
if (LMErr.NERR_Success != rc) {
throw new Win32Exception(rc);
}
}
}