Search in sources :

Example 1 with SHARE_INFO_2

use of com.sun.jna.platform.win32.LMShare.SHARE_INFO_2 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 2 with SHARE_INFO_2

use of com.sun.jna.platform.win32.LMShare.SHARE_INFO_2 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 3 with SHARE_INFO_2

use of com.sun.jna.platform.win32.LMShare.SHARE_INFO_2 in project jna by java-native-access.

the class MprTest method createLocalShare.

/**
     * Create a share on the local machine. Uses a temporary directory and
     * shares it out with ACCESS_ALL
     *
     * @param shareFolder
     *            the full path local folder to share
     * @return String with the share name, essentially the top level folder
     *         name.
     * @throws Exception
     *             the exception
     */
private String createLocalShare(File shareFolder) throws Exception {
    SHARE_INFO_2 shi = new SHARE_INFO_2();
    shi.shi2_netname = shareFolder.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 = shareFolder.getAbsolutePath();
    shi.shi2_passwd = "";
    // Write from struct to native memory.
    shi.write();
    IntByReference parm_err = new IntByReference(0);
    int errorCode = // Use local computer
    Netapi32.INSTANCE.NetShareAdd(// Use local computer
    null, 2, shi.getPointer(), parm_err);
    assertEquals(String.format("Failed to create share - errorCode: %d (Param: %d)", errorCode, parm_err.getValue()), LMErr.NERR_Success, errorCode);
    return shareFolder.getName();
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) SHARE_INFO_2(com.sun.jna.platform.win32.LMShare.SHARE_INFO_2)

Aggregations

SHARE_INFO_2 (com.sun.jna.platform.win32.LMShare.SHARE_INFO_2)3 IntByReference (com.sun.jna.ptr.IntByReference)3 File (java.io.File)2