Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.PointerByReference


     * Get information about a computer.
     * @param computerName
     * @return Domain or workgroup name.
     */
    public static String getDomainName(String computerName) {
        PointerByReference lpNameBuffer = new PointerByReference();
        IntByReference bufferType = new IntByReference();
   
        try {
            int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
            if (LMErr.NERR_Success != rc) {
                throw new Win32Exception(rc);     
            }   
            // type of domain: bufferType.getValue()
            return lpNameBuffer.getValue().getWideString(0);
        } finally {
            if (lpNameBuffer.getPointer() != null) {
                int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
                if (LMErr.NERR_Success != rc) {
                    throw new Win32Exception(rc);     
                }
            }
        }
View Full Code Here


     * Get the names of local groups on a computer.
     * @param serverName Name of the computer.
     * @return An array of local group names.
     */
    public static LocalGroup[] getLocalGroups(String serverName) {
        PointerByReference bufptr = new PointerByReference();
        IntByReference entriesRead = new IntByReference();
        IntByReference totalEntries = new IntByReference();   
        try {
            int rc = Netapi32.INSTANCE.NetLocalGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null);
            if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
                throw new Win32Exception(rc);
            }
            LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue());
            LMAccess.LOCALGROUP_INFO_1[] groups = (LOCALGROUP_INFO_1[]) group.toArray(entriesRead.getValue());
     
            ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
            for(LOCALGROUP_INFO_1 lgpi : groups) {
                LocalGroup lgp = new LocalGroup();
                if (lgpi.lgrui1_name != null) {
                  lgp.name = lgpi.lgrui1_name.toString();
                }
                if (lgpi.lgrui1_comment != null) {
                  lgp.comment = lgpi.lgrui1_comment.toString();
                }
                result.add(lgp);
            }
            return result.toArray(new LocalGroup[0]);
        } finally {     
            if (bufptr.getValue() != Pointer.NULL) {
                int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
                if (LMErr.NERR_Success != rc) {
                    throw new Win32Exception(rc);
                }
            }
        }
View Full Code Here

     * Get the names of global groups on a computer.
     * @param serverName Name of the computer.
     * @return An array of group names.
     */
    public static Group[] getGlobalGroups(String serverName) {
        PointerByReference bufptr = new PointerByReference();
        IntByReference entriesRead = new IntByReference();
        IntByReference totalEntries = new IntByReference();   
        try {
            int rc = Netapi32.INSTANCE.NetGroupEnum(serverName, 1, bufptr,
                                                    LMCons.MAX_PREFERRED_LENGTH, entriesRead,
                                                    totalEntries, null);
            if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
                throw new Win32Exception(rc);
            }
            LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue());
            LMAccess.GROUP_INFO_1[] groups = (LMAccess.GROUP_INFO_1[]) group.toArray(entriesRead.getValue());
     
            ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
            for(LMAccess.GROUP_INFO_1 lgpi : groups) {
                LocalGroup lgp = new LocalGroup();
                if (lgpi.grpi1_name != null) {
                  lgp.name = lgpi.grpi1_name.toString();
                }
                if (lgpi.grpi1_comment != null) {
                  lgp.comment = lgpi.grpi1_comment.toString();
                }
                result.add(lgp);
            }
            return result.toArray(new LocalGroup[0]);
        } finally {     
            if (bufptr.getValue() != Pointer.NULL) {
                int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
                if (LMErr.NERR_Success != rc) {
                    throw new Win32Exception(rc);
                }
            }
        }
View Full Code Here

     * Get the names of users on a computer.
     * @param serverName Name of the computer.
     * @return An array of users.
     */
    public static User[] getUsers(String serverName) {
        PointerByReference bufptr = new PointerByReference();
        IntByReference entriesRead = new IntByReference();
        IntByReference totalEntries = new IntByReference();   
        try {
            int rc = Netapi32.INSTANCE.NetUserEnum(
                serverName, 1, 0, bufptr,
                    LMCons.MAX_PREFERRED_LENGTH, entriesRead,
                    totalEntries, null);
            if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
                throw new Win32Exception(rc);
            }
            LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue());
            LMAccess.USER_INFO_1[] users = (LMAccess.USER_INFO_1[]) user.toArray(entriesRead.getValue());
            ArrayList<User> result = new ArrayList<User>();
            for(LMAccess.USER_INFO_1 lu : users) {
                User auser = new User();
                if (lu.usri1_name != null) {
                  auser.name = lu.usri1_name.toString();
                }
                result.add(auser);
            }
            return result.toArray(new User[0]);
        } finally {     
            if (bufptr.getValue() != Pointer.NULL) {
                int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
                if (LMErr.NERR_Success != rc) {
                    throw new Win32Exception(rc);
                }
            }
        }
View Full Code Here

     * @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);
                }
            }
      }
View Full Code Here

     * @param userName User name.
     * @param serverName Server name.
     * @return Groups.
     */
    public static Group[] getUserGroups(String userName, String serverName) {
      PointerByReference bufptr = new PointerByReference();
      IntByReference entriesread = new IntByReference();
      IntByReference totalentries = new IntByReference();
      try {
            int rc = Netapi32.INSTANCE.NetUserGetGroups(
                serverName, userName,
                    0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
            if (rc != LMErr.NERR_Success) {
                throw new Win32Exception(rc);
            }
            GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue());     
            GROUP_USERS_INFO_0[] lgroups = (GROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
            ArrayList<Group> result = new ArrayList<Group>();
            for (GROUP_USERS_INFO_0 lgpi : lgroups) {
                Group lgp = new Group();
                if (lgpi.grui0_name != null) {
                  lgp.name = lgpi.grui0_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);
                }
            }
      }
View Full Code Here

     * @return
     *  An array of domain trusts.
     */
    public static DomainTrust[] getDomainTrusts(String serverName) {
      IntByReference domainTrustCount = new IntByReference();
        PointerByReference domainsPointerRef = new PointerByReference();
        int rc = Netapi32.INSTANCE.DsEnumerateDomainTrusts(serverName,
                DsGetDC.DS_DOMAIN_VALID_FLAGS, domainsPointerRef, domainTrustCount);
      if(W32Errors.NO_ERROR != rc) {
            throw new Win32Exception(rc);
      }
      try {
            DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue());
            DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]);
            ArrayList<DomainTrust> trusts = new ArrayList<DomainTrust>(domainTrustCount.getValue());
            for(DS_DOMAIN_TRUSTS domainTrust : domainTrusts) {
                DomainTrust t = new DomainTrust();
                if (domainTrust.DnsDomainName != null) {
                  t.DnsDomainName = domainTrust.DnsDomainName.toString();
                }
                if (domainTrust.NetbiosDomainName != null) {
                  t.NetbiosDomainName = domainTrust.NetbiosDomainName.toString();
                }
                t.DomainSid = domainTrust.DomainSid;
                if (domainTrust.DomainSid != null) {
                  t.DomainSidString = Advapi32Util.convertSidToStringSid(domainTrust.DomainSid);
                }
                t.DomainGuid = domainTrust.DomainGuid;
                if (domainTrust.DomainGuid != null) {
                  t.DomainGuidString = Ole32Util.getStringFromGUID(domainTrust.DomainGuid);
                }
                t.flags = domainTrust.Flags;
                trusts.add(t);
            }
            return trusts.toArray(new DomainTrust[0]);
      } finally {
            rc = Netapi32.INSTANCE.NetApiBufferFree(domainsPointerRef.getValue());
            if(W32Errors.NO_ERROR != rc) {
                throw new Win32Exception(rc);
            }
      }
    }
View Full Code Here

    public static UserInfo getUserInfo(String accountName) {
        return getUserInfo(accountName, Netapi32Util.getDCName());
    }
 
    public static UserInfo getUserInfo(String accountName, String domainName) {
        PointerByReference bufptr = new PointerByReference();
        int rc = -1;
        try {
            rc = Netapi32.INSTANCE.NetUserGetInfo(domainName, accountName, (short)23, bufptr);
            if (rc == LMErr.NERR_Success) {
                USER_INFO_23 info_23 = new USER_INFO_23(bufptr.getValue());
                UserInfo userInfo = new UserInfo();
                if (info_23.usri23_comment != null) {
                  userInfo.comment = info_23.usri23_comment.toString();
                }
                userInfo.flags = info_23.usri23_flags;
                if (info_23.usri23_full_name != null) {
                  userInfo.fullName = info_23.usri23_full_name.toString();
                }
                if (info_23.usri23_name != null) {
                  userInfo.name = info_23.usri23_name.toString();
                }
                if (info_23.usri23_user_sid != null) {
                  userInfo.sidString = Advapi32Util.convertSidToStringSid(info_23.usri23_user_sid);
                }
                userInfo.sid = info_23.usri23_user_sid;
                return userInfo;
            } else {
                throw new Win32Exception(rc);
            }
        } finally {
            if (bufptr.getValue() != Pointer.NULL) {
                Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
            }
        }
    }
View Full Code Here

        HRESULT hr = Ole32.INSTANCE.CLSIDFromString(new WString(clsidStr),
                clsid);
        COMUtils.checkRC(hr);

        // load typelib
        PointerByReference pTypeLib = new PointerByReference();
        hr = OleAuto.INSTANCE.LoadRegTypeLib(clsid, wVerMajor, wVerMinor, lcid,
                pTypeLib);
        COMUtils.checkRC(hr);

        // init type lib class
        this.typelib = new TypeLib(pTypeLib.getValue());

        this.initTypeLibInfo();
    }
View Full Code Here

        this.initTypeLibInfo();
    }

    public TypeLibUtil(String file) {
        // load typelib
        PointerByReference pTypeLib = new PointerByReference();
        HRESULT hr = OleAuto.INSTANCE.LoadTypeLib(new WString(file), pTypeLib);
        COMUtils.checkRC(hr);

        // init type lib class
        this.typelib = new TypeLib(pTypeLib.getValue());

        this.initTypeLibInfo();
    }
View Full Code Here

TOP

Related Classes of com.sun.jna.ptr.PointerByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.