Beispiel #1
0
 public void testGetUserAccount() {
   USER_INFO_1 userInfo = new USER_INFO_1();
   userInfo.usri1_name = "JNANetapi32TestUser";
   userInfo.usri1_password = "******";
   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 {
       if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
         Kernel32.INSTANCE.CloseHandle(phUser.getValue());
       }
     }
   } finally {
     assertEquals(
         LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
   }
 }