Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.IntByReference


   * @return true if exists
   */
  public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name)
  {
    Advapi32 advapi32;
    IntByReference pType, lpcbData;
    byte[] lpData = new byte[1];
    int handle = 0;
    boolean ret = false;

    advapi32 = Advapi32.INSTANCE;
    pType = new IntByReference();
    lpcbData = new IntByReference();
    handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);

    if (handle != 0)
    {

View Full Code Here


   * @return true on success
   */
  public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name)
  {
    Advapi32 advapi32;
    IntByReference hkResult, dwDisposition;
    int handle = 0;
    boolean ret = false;

    advapi32 = Advapi32.INSTANCE;
    hkResult = new IntByReference();
    dwDisposition = new IntByReference();
    handle = openKey(rootKey, parent, WINNT.KEY_READ);

    if (handle != 0)
    {

      if (advapi32.RegCreateKeyEx(handle, name, 0, null, WINNT.REG_OPTION_NON_VOLATILE, WINNT.KEY_READ, null, hkResult, dwDisposition) == WINERROR.ERROR_SUCCESS)
      {
        ret = true;
        advapi32.RegCloseKey(hkResult.getValue());

      }
      else
      {
        ret = false;
View Full Code Here

  public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent)
  {
    Advapi32 advapi32;
    int handle = 0, dwIndex;
    char[] lpName;
    IntByReference lpcName;
    WINBASE.FILETIME lpftLastWriteTime;
    TreeSet<String> subKeys = new TreeSet<String>();

    advapi32 = Advapi32.INSTANCE;
    handle = openKey(rootKey, parent, WINNT.KEY_READ);
    lpName = new char[256];
    lpcName = new IntByReference(256);
    lpftLastWriteTime = new WINBASE.FILETIME();

    if (handle != 0)
    {
      dwIndex = 0;

      while (advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS)
      {
        subKeys.add(new String(lpName, 0, lpcName.getValue()));
        lpcName.setValue(256);
        dwIndex++;
      }
      advapi32.RegCloseKey(handle);
    }
View Full Code Here

  {
    Advapi32 advapi32;
    int handle = 0, dwIndex, result = 0;
    char[] lpValueName;
    byte[] lpData;
    IntByReference lpcchValueName, lpType, lpcbData;
    String name;
    TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);

    advapi32 = Advapi32.INSTANCE;
    handle = openKey(rootKey, key, WINNT.KEY_READ);
    lpValueName = new char[16384];
    lpcchValueName = new IntByReference(16384);
    lpType = new IntByReference();
    lpData = new byte[1];
    lpcbData = new IntByReference();

    if (handle != 0)
    {
      dwIndex = 0;

      do
      {
        lpcbData.setValue(0);
        result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);

        if (result == WINERROR.ERROR_MORE_DATA)
        {
          lpData = new byte[lpcbData.getValue()];
          lpcchValueName = new IntByReference(16384);
          result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData);

          if (result == WINERROR.ERROR_SUCCESS)
          {
            name = new String(lpValueName, 0, lpcchValueName.getValue());

            switch (lpType.getValue())
            {
            case WINNT.REG_SZ:
              values.put(name, convertBufferToString(lpData));
View Full Code Here

      _errorStream = _process.getErrorStream();

    }
    if (_cpuAffinity != AFFINITY_UNDEFINED)
    {
      IntByReference affinity = new IntByReference();
      affinity.setValue(_cpuAffinity);
      if (CLibrary.INSTANCE.sched_setaffinity(_pid, 4, affinity) == -1)
        System.out.println("error setting affinity");
    }

    System.out.println("started process " + _pid);
View Full Code Here

      state = 0;
      service = advapi32.OpenService(serviceManager, name, WINNT.GENERIC_READ);

      if (service != null)
      {
        IntByReference pcbBytesNeeded = new IntByReference();
        state |= Service.STATE_INSTALLED;
        // get size required
        if (!advapi32.QueryServiceConfig(service, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig(service, buffer, cbBufSize, pcbBytesNeeded))
          {
            QUERY_SERVICE_CONFIG lpServiceConfig = new QUERY_SERVICE_CONFIG();
            lpServiceConfig.init(buffer);
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DISABLED)
              state |= Service.STATE_DISABLED;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_BOOT_START | lpServiceConfig.dwStartType == Advapi32.SERVICE_SYSTEM_START
                | lpServiceConfig.dwStartType == Advapi32.SERVICE_AUTO_START)
              state |= Service.STATE_AUTOMATIC;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DEMAND_START)
              state |= Service.STATE_MANUAL;
            if ((lpServiceConfig.dwServiceType & Advapi32.SERVICE_INTERACTIVE_PROCESS) != 0)
              state |= Service.STATE_INTERACTIVE;
            result.setAccount(lpServiceConfig.lpServiceStartName);
            result.setCommand(lpServiceConfig.lpBinaryPathName);
            result.setDependencies(lpServiceConfig.getDependencies());
            result.setDisplayName(lpServiceConfig.lpDisplayName);

          }
          else
          {
            state |= Service.STATE_UNKNOWN;
            System.out.println("Error in QueryServiceConfig: " + Native.getLastError());
          }
        }
        else
        {
          state |= Service.STATE_UNKNOWN;
          System.out.println("Error in QueryServiceConfig: " + Native.getLastError());
        }
        if (!advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_STATUS_PROCESS lpBuffer = new SERVICE_STATUS_PROCESS();
            lpBuffer.init(buffer);
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_RUNNING)
              state |= Service.STATE_RUNNING;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_PAUSED)
              state |= Service.STATE_PAUSED;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_START_PENDING)
              state |= Service.STATE_STARTING;
            if (lpBuffer.dwCurrentState == advapi32.SERVICE_STOP_PENDING)
              state |= Service.STATE_STOPPING;
            result.setPid(lpBuffer.dwProcessId);
          }
          else
          {
            state |= Service.STATE_UNKNOWN;
            System.out.println("Error in QueryServiceStatusEx: " + Native.getLastError());
          }
        }
        if (!advapi32.QueryServiceConfig2(service, (byte) advapi32.SERVICE_CONFIG_DESCRIPTION, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig2(service, (byte) advapi32.SERVICE_CONFIG_DESCRIPTION, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_DESCRIPTION lpBuffer = new SERVICE_DESCRIPTION();
View Full Code Here

      service = advapi32.OpenService(serviceManager, serviceName, WINNT.GENERIC_READ);
      // System.out.println("Win32Service.state() service "+service);

      if (service != null)
      {
        IntByReference pcbBytesNeeded = new IntByReference();
        result |= Service.STATE_INSTALLED;
        // get size required
        if (!advapi32.QueryServiceConfig(service, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          if (cbBufSize > 8192)
            cbBufSize = 8192;
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceConfig(service, buffer, cbBufSize, pcbBytesNeeded))
          {
            QUERY_SERVICE_CONFIG lpServiceConfig = new QUERY_SERVICE_CONFIG();
            lpServiceConfig.init(buffer);
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DISABLED)
              result |= Service.STATE_DISABLED;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_BOOT_START | lpServiceConfig.dwStartType == Advapi32.SERVICE_SYSTEM_START
                | lpServiceConfig.dwStartType == Advapi32.SERVICE_AUTO_START)
              result |= Service.STATE_AUTOMATIC;
            if (lpServiceConfig.dwStartType == Advapi32.SERVICE_DEMAND_START)
              result |= Service.STATE_MANUAL;
            if ((lpServiceConfig.dwServiceType & Advapi32.SERVICE_INTERACTIVE_PROCESS) != 0)
              result |= Service.STATE_INTERACTIVE;

          }
          else
          {
            result |= Service.STATE_UNKNOWN;
            int error = Native.getLastError();
            System.out.println("Error getting buffer size in QueryServiceConfig: " + error + " " + Kernel32Util.formatMessageFromLastErrorCode(error));
          }
        }
        else
        {
          result |= Service.STATE_UNKNOWN;
          int error = Native.getLastError();
          System.out.println("Error in QueryServiceConfig: " + error + " " + Kernel32Util.formatMessageFromLastErrorCode(error));
        }
        if (!advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, null, 0, pcbBytesNeeded))
        {
          // now get the data
          int cbBufSize = pcbBytesNeeded.getValue();
          Memory buffer = new Memory(cbBufSize);
          buffer.clear();
          if (advapi32.QueryServiceStatusEx(service, (byte) advapi32.SC_STATUS_PROCESS_INFO, buffer, cbBufSize, pcbBytesNeeded))
          {
            SERVICE_STATUS_PROCESS lpBuffer = new SERVICE_STATUS_PROCESS();
View Full Code Here

    {
      Memory service_data = null;
      int service_data_size = 0;
      int infoLevel = WINSVC.SC_ENUM_PROCESS_INFO;
      boolean retVal;
      IntByReference bytesNeeded = new IntByReference(0);
      IntByReference srvCount = new IntByReference(0);
      IntByReference resumeHandle = new IntByReference(0);
      int srvType = WINSVC.SERVICE_WIN32;
      int srvState = WINSVC.SERVICE_STATE_ALL;

      // Call EnumServicesStatus with null data and data_size == 0, so we
      // get the required memory size
      retVal = Advapi32.INSTANCE.EnumServicesStatusExW(sc, infoLevel, srvType, srvState, service_data, service_data_size, bytesNeeded,
          srvCount, resumeHandle, null);

      int err = Native.getLastError();
      // EnumServicesStatus should need more memory space
      if ((!retVal) || err == WINERROR.ERROR_MORE_DATA)
      {
        int bytesCount = bytesNeeded.getValue();
        service_data = new Memory(bytesCount);
        service_data.clear();
        service_data_size = bytesCount;
        // System.out.println(resumeHandle.getValue());
        resumeHandle.setValue(0);
        retVal = Advapi32.INSTANCE.EnumServicesStatusExW(sc, infoLevel, srvType, srvState, service_data, service_data_size, bytesNeeded,
            srvCount, resumeHandle, null);
        if (!retVal)
        {
          err = Native.getLastError();
View Full Code Here

      }

      if (_cpuAffinity != AFFINITY_UNDEFINED)
      {
        IntByReference affinity = new IntByReference();
        affinity.setValue(_cpuAffinity);
        if (CLibrary.INSTANCE.sched_setaffinity(_pid, 4, affinity) == -1)
          log("error setting affinity");
      }

      executor.execute(new Runnable()
View Full Code Here

        CLibrary.INSTANCE.close(_errPipe[1]);

      }
      if (_cpuAffinity != AFFINITY_UNDEFINED)
      {
        IntByReference affinity = new IntByReference();
        affinity.setValue(_cpuAffinity);
        if (CLibrary.INSTANCE.sched_setaffinity(_pid, 4, affinity) == -1)
          log("error setting affinity");
      }
      _stopWaiter = true;
      executor.execute(new Runnable()
View Full Code Here

TOP

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

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.