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();
lpBuffer.init(buffer);
result.setDescription(lpBuffer.lpDescription);
}
else
{
state |= Service.STATE_UNKNOWN;