Search in sources :

Example 66 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class Netapi32Test method testNetGetJoinInformation.

public void testNetGetJoinInformation() {
    IntByReference bufferType = new IntByReference();
    assertEquals(W32Errors.ERROR_INVALID_PARAMETER, Netapi32.INSTANCE.NetGetJoinInformation(null, null, bufferType));
    PointerByReference lpNameBuffer = new PointerByReference();
    assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetGetJoinInformation(null, lpNameBuffer, bufferType));
    assertTrue(lpNameBuffer.getValue().getString(0).length() > 0);
    assertTrue(bufferType.getValue() > 0);
    assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 67 with IntByReference

use of com.sun.jna.ptr.IntByReference 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()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) LOCALGROUP_USERS_INFO_0(com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0)

Example 68 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class Netapi32Test method testNetShareAddShareInfo2.

public void testNetShareAddShareInfo2() throws Exception {
    File fileShareFolder = createTempFolder();
    SHARE_INFO_2 shi = new SHARE_INFO_2();
    shi.shi2_netname = fileShareFolder.getName();
    shi.shi2_type = LMShare.STYPE_DISKTREE;
    shi.shi2_remark = "";
    shi.shi2_permissions = LMAccess.ACCESS_ALL;
    shi.shi2_max_uses = -1;
    shi.shi2_current_uses = 0;
    shi.shi2_path = fileShareFolder.getAbsolutePath();
    shi.shi2_passwd = "";
    // Write from struct to native memory.
    shi.write();
    IntByReference parm_err = new IntByReference(0);
    int winError = // Use local computer
    Netapi32.INSTANCE.NetShareAdd(// Use local computer
    null, 2, shi.getPointer(), parm_err);
    if (winError == W32Errors.ERROR_INVALID_PARAMETER) {
        // fail with offset.
        throw new Exception("testNetShareAddShareInfo2 failed with invalid parameter on structure offset: " + parm_err.getValue());
    }
    assertEquals("Failed to add share", LMErr.NERR_Success, winError);
    Netapi32.INSTANCE.NetShareDel(null, shi.shi2_netname, 0);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) SHARE_INFO_2(com.sun.jna.platform.win32.LMShare.SHARE_INFO_2) File(java.io.File)

Example 69 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class Netapi32Test method testNetShareDel.

public void testNetShareDel() throws Exception {
    File fileShareFolder = createTempFolder();
    SHARE_INFO_2 shi = new SHARE_INFO_2();
    shi.shi2_netname = fileShareFolder.getName();
    shi.shi2_type = LMShare.STYPE_DISKTREE;
    shi.shi2_remark = "";
    shi.shi2_permissions = LMAccess.ACCESS_ALL;
    shi.shi2_max_uses = -1;
    shi.shi2_current_uses = 0;
    shi.shi2_path = fileShareFolder.getAbsolutePath();
    shi.shi2_passwd = "";
    // Write from struct to native memory.
    shi.write();
    IntByReference parm_err = new IntByReference(0);
    assertEquals("Failed to add share", LMErr.NERR_Success, // Use local computer
    Netapi32.INSTANCE.NetShareAdd(// Use local computer
    null, 2, shi.getPointer(), parm_err));
    assertEquals("Failed to delete share", LMErr.NERR_Success, Netapi32.INSTANCE.NetShareDel(null, shi.shi2_netname, 0));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) SHARE_INFO_2(com.sun.jna.platform.win32.LMShare.SHARE_INFO_2) File(java.io.File)

Example 70 with IntByReference

use of com.sun.jna.ptr.IntByReference in project jna by java-native-access.

the class Netapi32Test method testNetGroupEnum.

public void testNetGroupEnum() {
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesread = new IntByReference();
    IntByReference totalentries = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGroupEnum(null, 2, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
    GROUP_INFO_2 group = new GROUP_INFO_2(bufptr.getValue());
    GROUP_INFO_2[] groups = (GROUP_INFO_2[]) group.toArray(entriesread.getValue());
    for (GROUP_INFO_2 grpi : groups) {
        assertTrue(grpi.grpi2_name.length() > 0);
    }
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) GROUP_INFO_2(com.sun.jna.platform.win32.LMAccess.GROUP_INFO_2) PointerByReference(com.sun.jna.ptr.PointerByReference)

Aggregations

IntByReference (com.sun.jna.ptr.IntByReference)199 PointerByReference (com.sun.jna.ptr.PointerByReference)38 Memory (com.sun.jna.Memory)33 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)26 File (java.io.File)19 Pointer (com.sun.jna.Pointer)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 PSID (com.sun.jna.platform.win32.WinNT.PSID)13 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)11 SC_HANDLE (com.sun.jna.platform.win32.Winsvc.SC_HANDLE)11 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)9 ACL (com.sun.jna.platform.win32.WinNT.ACL)8 Advapi32 (com.sun.jna.platform.win32.Advapi32)7 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 ACCESS_ALLOWED_ACE (com.sun.jna.platform.win32.WinNT.ACCESS_ALLOWED_ACE)6 SECURITY_DESCRIPTOR (com.sun.jna.platform.win32.WinNT.SECURITY_DESCRIPTOR)6 HKEY (com.sun.jna.platform.win32.WinReg.HKEY)6 EVT_HANDLE (com.sun.jna.platform.win32.Winevt.EVT_HANDLE)6 CredHandle (com.sun.jna.platform.win32.Sspi.CredHandle)5