if (ret != -1)
return ret;
- printOutput(printInfo);
- return 1;
+ return printOutput(printInfo);
}
int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& printInfo) {
L"and \"67%%\" is the returned value.\n"
L"The performance data is found behind the \"|\", in order:\n"
L"returned value, warning threshold, critical threshold, minimal value and,\n"
- L"if applicable, the maximal value. Performance data will only be displayed when\n"
- L"you set at least one threshold\n\n"
+ L"if applicable, the maximal value.\n\n"
L"%s' exit codes denote the following:\n"
L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
LPBYTE lpServices = NULL;
DWORD cbBufSize = 0;
- DWORD *pcbBytesNeeded = NULL, *lpServicesReturned = NULL, *lpResumeHandle = NULL;
+ DWORD pcbBytesNeeded = NULL, ServicesReturned = NULL, ResumeHandle = NULL;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
- lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL)
+ lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL)
&& GetLastError() != ERROR_MORE_DATA)
goto die;
- lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
- cbBufSize = *pcbBytesNeeded;
+ lpServices = reinterpret_cast<LPBYTE>(new BYTE[pcbBytesNeeded]);
+ cbBufSize = pcbBytesNeeded;
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
- lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL))
+ lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL))
goto die;
LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices;
- for (DWORD i = 0; i< *lpServicesReturned; i++) {
+ for (DWORD i = 0; i < ServicesReturned; i++) {
if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName)) {
+ int state = pInfo[i].ServiceStatusProcess.dwCurrentState;
delete lpServices;
- return pInfo[i].ServiceStatusProcess.dwCurrentState;
+ return state;
}
}
+ wcout << L"Service " << printInfo.service << L" could not be found\n";
+ delete[] reinterpret_cast<LPBYTE>(lpServices);
+ return -1;
die:
+ die();
if (lpServices)
delete[] reinterpret_cast<LPBYTE>(lpServices);
- wcout << L"Service " << printInfo.service << L" could not be found" << endl;
return -1;
}