use of com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0 in project jna by java-native-access.
the class Netapi32Test method testNetUserGetLocalGroups.
public void testNetUserGetLocalGroups() {
String currentUser = Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible);
PointerByReference bufptr = new PointerByReference();
IntByReference entriesread = new IntByReference();
IntByReference totalentries = new IntByReference();
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserGetLocalGroups(null, currentUser, 0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries));
LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
for (LOCALGROUP_USERS_INFO_0 localGroupInfo : lgroups) {
assertTrue(localGroupInfo.lgrui0_name.length() > 0);
}
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
use of com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0 in project jna by java-native-access.
the class Netapi32Util method getUserLocalGroups.
/**
* Get local groups of a given user on a given system.
* @param userName User name.
* @param serverName Server name.
* @return Local groups.
*/
public static Group[] getUserLocalGroups(String userName, String serverName) {
PointerByReference bufptr = new PointerByReference();
IntByReference entriesread = new IntByReference();
IntByReference totalentries = new IntByReference();
try {
int rc = Netapi32.INSTANCE.NetUserGetLocalGroups(serverName, userName, 0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
if (rc != LMErr.NERR_Success) {
throw new Win32Exception(rc);
}
LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
ArrayList<Group> result = new ArrayList<Group>();
for (LOCALGROUP_USERS_INFO_0 lgpi : lgroups) {
LocalGroup lgp = new LocalGroup();
if (lgpi.lgrui0_name != null) {
lgp.name = lgpi.lgrui0_name.toString();
}
result.add(lgp);
}
return result.toArray(new Group[0]);
} finally {
if (bufptr.getValue() != Pointer.NULL) {
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
if (LMErr.NERR_Success != rc) {
throw new Win32Exception(rc);
}
}
}
}
Aggregations