use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.
the class Advapi32UtilTest method testGetCurrentUserGroups.
public void testGetCurrentUserGroups() {
Account[] groups = Advapi32Util.getCurrentUserGroups();
assertTrue(groups.length > 0);
for (Account group : groups) {
assertTrue(group.name.length() > 0);
assertTrue(group.sidString.length() > 0);
assertTrue(group.sid.length > 0);
}
}
use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.
the class Advapi32UtilTest method testGetAccountBySid.
public void testGetAccountBySid() {
String accountName = Advapi32Util.getUserName();
Account currentUser = Advapi32Util.getAccountByName(accountName);
Account account = Advapi32Util.getAccountBySid(new PSID(currentUser.sid));
assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
assertEquals(currentUser.fqn.toLowerCase(), account.fqn.toLowerCase());
assertEquals(currentUser.name.toLowerCase(), account.name.toLowerCase());
assertEquals(currentUser.domain.toLowerCase(), account.domain.toLowerCase());
assertEquals(currentUser.sidString, account.sidString);
}
use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.
the class Advapi32UtilTest method main.
public static void main(String[] args) {
junit.textui.TestRunner.run(Advapi32UtilTest.class);
String currentUserName = Advapi32Util.getUserName();
System.out.println("GetUserName: " + currentUserName);
for (Account group : Advapi32Util.getCurrentUserGroups()) {
System.out.println(" " + group.fqn + " [" + group.sidString + "]");
}
Account accountByName = Advapi32Util.getAccountByName(currentUserName);
System.out.println("AccountByName: " + currentUserName);
System.out.println(" Fqn: " + accountByName.fqn);
System.out.println(" Domain: " + accountByName.domain);
System.out.println(" Sid: " + accountByName.sidString);
Account accountBySid = Advapi32Util.getAccountBySid(new PSID(accountByName.sid));
System.out.println("AccountBySid: " + accountByName.sidString);
System.out.println(" Fqn: " + accountBySid.fqn);
System.out.println(" Name: " + accountBySid.name);
System.out.println(" Domain: " + accountBySid.domain);
}
use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.
the class Advapi32UtilTest method testGetAccountByName.
public void testGetAccountByName() {
String accountName = Advapi32Util.getUserName();
Account account = Advapi32Util.getAccountByName(accountName);
assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
}
use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.
the class Advapi32UtilTest method testGetUserAccount.
public void testGetUserAccount() {
USER_INFO_1 userInfo = new USER_INFO_1();
userInfo.usri1_name = "JNANetapi32TestUser";
userInfo.usri1_password = "!JNAP$$Wrd0";
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
// ignore test if not able to add user (need to be administrator to do this).
if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
return;
}
try {
HANDLEByReference phUser = new HANDLEByReference();
try {
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
assertTrue(account.name.length() > 0);
assertEquals(userInfo.usri1_name.toString(), account.name);
} finally {
HANDLE hUser = phUser.getValue();
if (!WinBase.INVALID_HANDLE_VALUE.equals(hUser)) {
Kernel32Util.closeHandle(hUser);
}
}
} finally {
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
}
}
Aggregations