* Get the names of global groups on a computer.
* @param serverName Name of the computer.
* @return An array of group names.
*/
public static Group[] getGlobalGroups(String serverName) {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesRead = new IntByReference();
IntByReference totalEntries = new IntByReference();
try {
int rc = Netapi32.INSTANCE.NetGroupEnum(serverName, 1, bufptr,
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
totalEntries, null);
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
throw new Win32Exception(rc);
}
LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue());
LMAccess.GROUP_INFO_1[] groups = (LMAccess.GROUP_INFO_1[]) group.toArray(entriesRead.getValue());
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
for(LMAccess.GROUP_INFO_1 lgpi : groups) {
LocalGroup lgp = new LocalGroup();
lgp.name = lgpi.grpi1_name.toString();
lgp.comment = lgpi.grpi1_comment.toString();;
result.add(lgp);
}
return result.toArray(new LocalGroup[0]);
} finally {
if (bufptr.getValue() != Pointer.NULL) {
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
if (LMErr.NERR_Success != rc) {
throw new Win32Exception(rc);
}
}
}