use of com.sun.jna.platform.win32.LMAccess.LOCALGROUP_INFO_1 in project jna by java-native-access.
the class Netapi32Util method getLocalGroups.
/**
* Get the names of local groups on a computer.
* @param serverName Name of the computer.
* @return An array of local group names.
*/
public static LocalGroup[] getLocalGroups(String serverName) {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesRead = new IntByReference();
IntByReference totalEntries = new IntByReference();
try {
int rc = Netapi32.INSTANCE.NetLocalGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null);
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
throw new Win32Exception(rc);
}
LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue());
LMAccess.LOCALGROUP_INFO_1[] groups = (LOCALGROUP_INFO_1[]) group.toArray(entriesRead.getValue());
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
for (LOCALGROUP_INFO_1 lgpi : groups) {
LocalGroup lgp = new LocalGroup();
if (lgpi.lgrui1_name != null) {
lgp.name = lgpi.lgrui1_name.toString();
}
if (lgpi.lgrui1_comment != null) {
lgp.comment = lgpi.lgrui1_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);
}
}
}
}
Aggregations