From d347a47a33d3f108016df1ae1e309e3d1b789b9d Mon Sep 17 00:00:00 2001 From: Lee Wilmott Date: Wed, 23 Apr 2025 13:06:12 +0100 Subject: [PATCH 1/3] Create service and appcmd timeout commandline parameters --- README.md | 28 ++++++ src/ServiceMonitor/IISConfigUtil.cpp | 14 ++- src/ServiceMonitor/IISConfigUtil.h | 4 +- src/ServiceMonitor/Main.cpp | 108 ++++++++++++++++++---- src/ServiceMonitor/ServiceMonitor.cpp | 6 +- src/ServiceMonitor/ServiceMonitor.rc | Bin 5584 -> 5594 bytes src/ServiceMonitor/ServiceMonitor.vcxproj | 1 + src/ServiceMonitor/resource.h | 19 ++++ src/ServiceMonitor/version.h | Bin 466 -> 466 bytes 9 files changed, 148 insertions(+), 32 deletions(-) create mode 100644 src/ServiceMonitor/resource.h diff --git a/README.md b/README.md index 69ca473..cc83144 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,34 @@ for those Environment variable / value pairs present in this list below. ## Usage +``` +ServiceMonitor.exe [ [application_pool]] [-st ] [-at ] +``` + +|Placeholder|Description| +|---|---| +|`windows_service_name`|Name of the Windows service to monitor| +|`application_pool`|Name of the application pool to monitor; defaults to DefaultAppPool| +|`service_timeout`|The time (in seconds) it is willing to wait for the service to start or stop| +|`appcmd_timeout`|The time (in seconds) it is willing to wait for the appcmd command to execute| + +### Examples + +``` +ServiceMonitor.exe +``` +``` +ServiceMonitor.exe -st 60 +``` +``` +ServiceMonitor.exe w3svc ApplicationPool +``` +``` +ServiceMonitor.exe -at 30 +``` +``` +ServiceMonitor.exe w3svc MyAppPool -st 60 -at 30 +``` ``` .\ServiceMonitor.exe w3svc ``` diff --git a/src/ServiceMonitor/IISConfigUtil.cpp b/src/ServiceMonitor/IISConfigUtil.cpp index 7342147..e587646 100644 --- a/src/ServiceMonitor/IISConfigUtil.cpp +++ b/src/ServiceMonitor/IISConfigUtil.cpp @@ -199,7 +199,7 @@ HRESULT IISConfigUtil::BuildAppCmdCommand(const vector>& } -HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError) +HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError, int appcmdTimeoutSeconds) { HRESULT hr = S_OK; STARTUPINFO si = { sizeof(STARTUPINFO) }; @@ -226,9 +226,9 @@ HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError) } // - // wait for at most 5 seconds to allow APPCMD finish + // wait to allow APPCMD finish (default is 5 seconds) // - WaitForSingleObject(pi.hProcess, 5000); + WaitForSingleObject(pi.hProcess, appcmdTimeoutSeconds * 1000); if ((!GetExitCodeProcess(pi.hProcess, &dwStatus) || dwStatus != 0) && (!fIgnoreError)) { // @@ -246,7 +246,7 @@ HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError) return hr; } -HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName) +HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, int appcmdTimeoutSeconds) { HRESULT hr = S_OK; LPTCH lpvEnv = NULL; @@ -293,7 +293,6 @@ HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName) envVec.emplace_back(wstring(pstrName), wstring(pstrValue)); pEqualChar[0] = L'='; - } // // move to next environment variable @@ -304,7 +303,6 @@ HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName) envVecIter = envVec.begin(); while (fMoreData) { - pstrRmCmd.clear(); fMoreData = FALSE; hr = BuildAppCmdCommand(envVec, envVecIter, pstrAppPoolName, pstrRmCmd, APPCMD_RM); @@ -323,7 +321,7 @@ HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName) // //allow appcmd to fail if it is trying to remove environment variable // - RunCommand(pstrRmCmd, TRUE); + RunCommand(pstrRmCmd, TRUE, appcmdTimeoutSeconds); } fMoreData = TRUE; @@ -348,7 +346,7 @@ HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName) // //appcmd must succeed when add new environment variables // - hr = RunCommand(pstrAddCmd, FALSE); + hr = RunCommand(pstrAddCmd, FALSE, appcmdTimeoutSeconds); if (FAILED(hr)) { diff --git a/src/ServiceMonitor/IISConfigUtil.h b/src/ServiceMonitor/IISConfigUtil.h index 8bcafaa..7226bb5 100644 --- a/src/ServiceMonitor/IISConfigUtil.h +++ b/src/ServiceMonitor/IISConfigUtil.h @@ -19,10 +19,10 @@ class IISConfigUtil IISConfigUtil(); ~IISConfigUtil(); HRESULT Initialize(); - HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName); + HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, int appcmdTimeoutSeconds); private: - HRESULT RunCommand(std::wstring& pstrCmd, BOOL fIgnoreError); + HRESULT RunCommand(std::wstring& pstrCmd, BOOL fIgnoreError, int appcmdTimeoutSeconds); void Replace(std::wstring& str, std::wstring oldValue, std::wstring newValue); HRESULT BuildAppCmdCommand(const std::vector>& vecSet, std::vector>::iterator& envVecIter, WCHAR* pstrAppPoolName, std::wstring& pStrCmd, APPCMD_CMD_TYPE appcmdType); BOOL FilterEnv(const std::unordered_map& filter, LPCTSTR strEnvName, LPCTSTR strEnvValue); diff --git a/src/ServiceMonitor/Main.cpp b/src/ServiceMonitor/Main.cpp index 26d6aa4..115b1e5 100644 --- a/src/ServiceMonitor/Main.cpp +++ b/src/ServiceMonitor/Main.cpp @@ -2,6 +2,7 @@ // Licensed under the MIT license. #include"stdafx.h" +#include "Version.h" HANDLE g_hStopEvent = INVALID_HANDLE_VALUE; @@ -26,25 +27,99 @@ BOOL WINAPI CtrlHandle(DWORD dwCtrlType) return TRUE; } +bool isNumber(LPCTSTR strpointer) { + + int index; + + for (index = 0; index < wcslen(strpointer); index++) { + if ((strpointer[index] < 48) || (strpointer[index] > 57)) { + return false; + } + } + + return true; +} + int __cdecl _tmain(int argc, _TCHAR* argv[]) { HRESULT hr = S_OK; Service_Monitor sm = Service_Monitor(); + int argIndex; + int serviceTimeout = 20; //default value - in seconds + int appcmdTimeout = 5; //default value - in seconds + bool invalidSyntax = false; + int nextPositionalArgument = 1; + + TCHAR buffDrive[3], buffDirName[1024], buffFileName[1024], buffExt[25]; + _wsplitpath_s(argv[0], buffDrive, 3, buffDirName, 1024, buffFileName, 1024, buffExt, 25); + + WCHAR fileName[1024]; + wcscpy_s(fileName, buffFileName); + wcscat_s(fileName, 1024, buffExt); - if (argc <= 1) + WCHAR* pstrServiceName = L"w3svc"; //default service name + WCHAR* pstrAppPoolName = L"DefaultAppPool"; // default application pool name + + for (argIndex = 1; argIndex < argc; argIndex++) { + if ((argIndex == 1) && ( + (_wcsicmp(argv[argIndex], L"-?") == 0) || + (_wcsicmp(argv[argIndex], L"/?") == 0) || + (_wcsicmp(argv[argIndex], L"--help") == 0) + )) { + invalidSyntax = true; + break; + } else if (_wcsicmp(argv[argIndex], L"-st") == 0) { + if (isNumber(argv[argIndex + 1])) { + serviceTimeout = _wtoi(argv[argIndex + 1]); + argIndex++; + } else { + invalidSyntax = true; + } + } else if (_wcsicmp(argv[argIndex], L"-at") == 0) { + if (isNumber(argv[argIndex + 1])) { + appcmdTimeout = _wtoi(argv[argIndex + 1]); + argIndex++; + } else { + invalidSyntax = true; + } + } else if (nextPositionalArgument == 1) { + pstrServiceName = argv[argIndex]; + nextPositionalArgument++; + } else if (nextPositionalArgument == 2) { + pstrAppPoolName = argv[argIndex]; + nextPositionalArgument++; + } else { + invalidSyntax = true; + } + } + + if (invalidSyntax) { - _tprintf(L"\nUSAGE: %s [windows service name]", argv[0]); - _tprintf(L"\n %s w3svc [application pool]", argv[0]); - _tprintf(L"\n\nOptions:"); - _tprintf(L"\n windows service name Name of the Windows service to monitor"); - _tprintf(L"\n application pool Name of the application pool to monitor; defaults to DefaultAppPool\n"); + _tprintf(L"\nServiceMonitor Version %d.%d.%d.%d", SM_MAJORNUMBER, SM_MINORNUMBER, SM_BUILDNUMBER, SM_BUILDMINORVERSION); + _tprintf(L"\n\nUSAGE:"); + _tprintf(L"\n %s [ [application_pool]] [-st ] [-at ]", fileName); + _tprintf(L"\n\nOptions:"); + _tprintf(L"\n windows_service_name Name of the Windows service to monitor"); + _tprintf(L"\n application_pool Name of the application pool to monitor; defaults to DefaultAppPool"); + _tprintf(L"\n service_timeout The time (in seconds) it is willing to wait for the service to start or stop"); + _tprintf(L"\n appcmd_timeout The time (in seconds) it is willing to wait for the appcmd command to execute"); + _tprintf(L"\n\nExamples:"); + _tprintf(L"\n %s", fileName); + _tprintf(L"\n %s w3svc", fileName); + _tprintf(L"\n %s -st 60", fileName); + _tprintf(L"\n %s w3svc ApplicationPool", fileName); + _tprintf(L"\n %s -at 30", fileName); + _tprintf(L"\n %s w3svc MyAppPool -st 60 -at 30", fileName); + goto Finished; } + _tprintf(L"Executing %s: %s [timeout: %d], ApplicationPool: %s [timeout: %d]", fileName, pstrServiceName, serviceTimeout, pstrAppPoolName, appcmdTimeout); + // iis only allow monitor on w3svc - if (_wcsicmp(argv[1], L"w3svc") == 0) + if (_wcsicmp(pstrServiceName, L"w3svc") == 0) { - hr = sm.StopServiceByName(L"w3svc"); + hr = sm.StopServiceByName(L"w3svc", serviceTimeout); if (FAILED(hr)) { hr = HRESULT_FROM_WIN32(GetLastError()); @@ -55,14 +130,9 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) // iis scenario, update the environment variable // we hardcode this behavior for now. We can add an input switch later if needed // - WCHAR* pstrAppPoolName = L"DefaultAppPool"; - if (argc > 2) - { - pstrAppPoolName = argv[2]; - } IISConfigUtil configHelper = IISConfigUtil(); - if( FAILED(hr = configHelper.Initialize()) || - FAILED(hr = configHelper.UpdateEnvironmentVarsToConfig(pstrAppPoolName))) + if (FAILED(hr = configHelper.Initialize()) || + FAILED(hr = configHelper.UpdateEnvironmentVarsToConfig(pstrAppPoolName, appcmdTimeout))) { _tprintf(L"\nFailed to update IIS configuration\n"); goto Finished; @@ -73,7 +143,7 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) NULL, // default security attributes TRUE, // manual-reset event FALSE, // initial state is nonsignaled - argv[1] // object name + pstrServiceName // object name ); if (g_hStopEvent == NULL) @@ -91,7 +161,7 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) if (g_hStopEvent != INVALID_HANDLE_VALUE) { - hr = sm.StartServiceByName(argv[1]); + hr = sm.StartServiceByName(pstrServiceName, serviceTimeout); } if (SUCCEEDED(hr)) @@ -101,7 +171,7 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) // // will stop monitoring once the stop event is set // - hr = sm.MonitoringService(argv[1], + hr = sm.MonitoringService(pstrServiceName, SERVICE_NOTIFY_STOPPED | SERVICE_NOTIFY_STOP_PENDING | SERVICE_NOTIFY_PAUSED | SERVICE_NOTIFY_PAUSE_PENDING, g_hStopEvent); } @@ -109,7 +179,7 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) // // don't capture the stop error // - sm.StopServiceByName(argv[1]); + sm.StopServiceByName(pstrServiceName, serviceTimeout); Finished: if (g_hStopEvent != INVALID_HANDLE_VALUE) diff --git a/src/ServiceMonitor/ServiceMonitor.cpp b/src/ServiceMonitor/ServiceMonitor.cpp index 541d720..6875cb4 100644 --- a/src/ServiceMonitor/ServiceMonitor.cpp +++ b/src/ServiceMonitor/ServiceMonitor.cpp @@ -67,7 +67,7 @@ HRESULT Service_Monitor::StartServiceByName(LPCTSTR pServiceName, DWORD dwTimeOu // // Query service status to make sure service is in running state // - while(dwRemainTime >0) + while (dwRemainTime > 0) { DWORD dwBytes = 0; SERVICE_STATUS_PROCESS sStatus; @@ -109,7 +109,7 @@ HRESULT Service_Monitor::StartServiceByName(LPCTSTR pServiceName, DWORD dwTimeOu } Finished: - if(SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { _tprintf(L"\n Service '%s' started \n", pServiceName); } @@ -211,7 +211,7 @@ HRESULT Service_Monitor::MonitoringService(LPCTSTR pServiceName, DWORD dwStatus, SERVICE_NOTIFY sNotify; hr = GetServiceHandle(pServiceName, &hService); - if(FAILED(hr)) + if (FAILED(hr)) { goto Finished; } diff --git a/src/ServiceMonitor/ServiceMonitor.rc b/src/ServiceMonitor/ServiceMonitor.rc index 7f7545a62dd0cdbbe4b4cfc5cbf608ff257bd43c..ad73388b5021203249abdc37c08802a8f42fb334 100644 GIT binary patch delta 26 gcmcbheM@_ThXAK8gAs!P5SvckFQB`*L?DJ00BGI^F8}}l delta 12 TcmcbmeL;JJhrs3_feuyxBcueY diff --git a/src/ServiceMonitor/ServiceMonitor.vcxproj b/src/ServiceMonitor/ServiceMonitor.vcxproj index 69a70f3..05ec145 100644 --- a/src/ServiceMonitor/ServiceMonitor.vcxproj +++ b/src/ServiceMonitor/ServiceMonitor.vcxproj @@ -152,6 +152,7 @@ + diff --git a/src/ServiceMonitor/resource.h b/src/ServiceMonitor/resource.h new file mode 100644 index 0000000..724683d --- /dev/null +++ b/src/ServiceMonitor/resource.h @@ -0,0 +1,19 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by ServiceMonitor.rc +// +#define SM_MAJORNUMBER 2 +#define SM_MINORNUMBER 1 +#define SM_BUILDNUMBER 0 +#define SM_BUILDMINORVERSION 0 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/ServiceMonitor/version.h b/src/ServiceMonitor/version.h index 91b864f2918146b8a1108df30b0c126359d617aa..708baf1114d16a87ac675420c064551bdab2876e 100644 GIT binary patch delta 18 acmcb_e2IC&14hG%4_zld;Fzq(xC8)BQwQS! delta 18 acmcb_e2IC&14e_14_zld;Fzq(xC8)BNC)Bo From d45f80f596c418a5fcdd4881ad7eaa671921f48e Mon Sep 17 00:00:00 2001 From: Lee Wilmott Date: Thu, 7 Aug 2025 19:00:18 +0100 Subject: [PATCH 2/3] Create 'service timeout' and 'appcmd timeout' command line parameters --- src/ServiceMonitor/Main.cpp | 41 +++++++++++++++-------- src/ServiceMonitor/ServiceMonitor.vcxproj | 1 - src/ServiceMonitor/resource.h | 19 ----------- 3 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 src/ServiceMonitor/resource.h diff --git a/src/ServiceMonitor/Main.cpp b/src/ServiceMonitor/Main.cpp index 115b1e5..21508ef 100644 --- a/src/ServiceMonitor/Main.cpp +++ b/src/ServiceMonitor/Main.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -#include"stdafx.h" +#include "stdafx.h" #include "Version.h" HANDLE g_hStopEvent = INVALID_HANDLE_VALUE; @@ -27,12 +27,12 @@ BOOL WINAPI CtrlHandle(DWORD dwCtrlType) return TRUE; } -bool isNumber(LPCTSTR strpointer) { +bool isNumber(LPCWSTR strpointer) { int index; for (index = 0; index < wcslen(strpointer); index++) { - if ((strpointer[index] < 48) || (strpointer[index] > 57)) { + if (iswdigit(strpointer[index]) == false) { return false; } } @@ -50,7 +50,7 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) bool invalidSyntax = false; int nextPositionalArgument = 1; - TCHAR buffDrive[3], buffDirName[1024], buffFileName[1024], buffExt[25]; + WCHAR buffDrive[3], buffDirName[1024], buffFileName[1024], buffExt[25]; _wsplitpath_s(argv[0], buffDrive, 3, buffDirName, 1024, buffFileName, 1024, buffExt, 25); WCHAR fileName[1024]; @@ -65,30 +65,43 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) (_wcsicmp(argv[argIndex], L"-?") == 0) || (_wcsicmp(argv[argIndex], L"/?") == 0) || (_wcsicmp(argv[argIndex], L"--help") == 0) - )) { + )) { invalidSyntax = true; break; - } else if (_wcsicmp(argv[argIndex], L"-st") == 0) { - if (isNumber(argv[argIndex + 1])) { + } + else if (_wcsicmp(argv[argIndex], L"-st") == 0) { + if (argIndex + 1 >= argc) { + invalidSyntax = true; + } + else if (isNumber(argv[argIndex + 1])) { serviceTimeout = _wtoi(argv[argIndex + 1]); argIndex++; - } else { + } + else { invalidSyntax = true; } - } else if (_wcsicmp(argv[argIndex], L"-at") == 0) { - if (isNumber(argv[argIndex + 1])) { + } + else if (_wcsicmp(argv[argIndex], L"-at") == 0) { + if (argIndex + 1 >= argc) { + invalidSyntax = true; + } + else if (isNumber(argv[argIndex + 1])) { appcmdTimeout = _wtoi(argv[argIndex + 1]); argIndex++; - } else { + } + else { invalidSyntax = true; } - } else if (nextPositionalArgument == 1) { + } + else if (nextPositionalArgument == 1) { pstrServiceName = argv[argIndex]; nextPositionalArgument++; - } else if (nextPositionalArgument == 2) { + } + else if (nextPositionalArgument == 2) { pstrAppPoolName = argv[argIndex]; nextPositionalArgument++; - } else { + } + else { invalidSyntax = true; } } diff --git a/src/ServiceMonitor/ServiceMonitor.vcxproj b/src/ServiceMonitor/ServiceMonitor.vcxproj index 05ec145..69a70f3 100644 --- a/src/ServiceMonitor/ServiceMonitor.vcxproj +++ b/src/ServiceMonitor/ServiceMonitor.vcxproj @@ -152,7 +152,6 @@ - diff --git a/src/ServiceMonitor/resource.h b/src/ServiceMonitor/resource.h deleted file mode 100644 index 724683d..0000000 --- a/src/ServiceMonitor/resource.h +++ /dev/null @@ -1,19 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by ServiceMonitor.rc -// -#define SM_MAJORNUMBER 2 -#define SM_MINORNUMBER 1 -#define SM_BUILDNUMBER 0 -#define SM_BUILDMINORVERSION 0 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif From 94f472fb4bd85663c4283027dbb55823be69ccb9 Mon Sep 17 00:00:00 2001 From: Lee Wilmott Date: Sat, 11 Oct 2025 00:39:02 +0100 Subject: [PATCH 3/3] Change timeout variable types from int to DWORD --- src/ServiceMonitor/IISConfigUtil.cpp | 4 ++-- src/ServiceMonitor/IISConfigUtil.h | 4 ++-- src/ServiceMonitor/Main.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ServiceMonitor/IISConfigUtil.cpp b/src/ServiceMonitor/IISConfigUtil.cpp index e587646..70a6e26 100644 --- a/src/ServiceMonitor/IISConfigUtil.cpp +++ b/src/ServiceMonitor/IISConfigUtil.cpp @@ -199,7 +199,7 @@ HRESULT IISConfigUtil::BuildAppCmdCommand(const vector>& } -HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError, int appcmdTimeoutSeconds) +HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError, DWORD appcmdTimeoutSeconds) { HRESULT hr = S_OK; STARTUPINFO si = { sizeof(STARTUPINFO) }; @@ -246,7 +246,7 @@ HRESULT IISConfigUtil::RunCommand(wstring& pstrCmd, BOOL fIgnoreError, int appcm return hr; } -HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, int appcmdTimeoutSeconds) +HRESULT IISConfigUtil::UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, DWORD appcmdTimeoutSeconds) { HRESULT hr = S_OK; LPTCH lpvEnv = NULL; diff --git a/src/ServiceMonitor/IISConfigUtil.h b/src/ServiceMonitor/IISConfigUtil.h index 7226bb5..022099a 100644 --- a/src/ServiceMonitor/IISConfigUtil.h +++ b/src/ServiceMonitor/IISConfigUtil.h @@ -19,10 +19,10 @@ class IISConfigUtil IISConfigUtil(); ~IISConfigUtil(); HRESULT Initialize(); - HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, int appcmdTimeoutSeconds); + HRESULT UpdateEnvironmentVarsToConfig(WCHAR* pstrAppPoolName, DWORD appcmdTimeoutSeconds); private: - HRESULT RunCommand(std::wstring& pstrCmd, BOOL fIgnoreError, int appcmdTimeoutSeconds); + HRESULT RunCommand(std::wstring& pstrCmd, BOOL fIgnoreError, DWORD appcmdTimeoutSeconds); void Replace(std::wstring& str, std::wstring oldValue, std::wstring newValue); HRESULT BuildAppCmdCommand(const std::vector>& vecSet, std::vector>::iterator& envVecIter, WCHAR* pstrAppPoolName, std::wstring& pStrCmd, APPCMD_CMD_TYPE appcmdType); BOOL FilterEnv(const std::unordered_map& filter, LPCTSTR strEnvName, LPCTSTR strEnvValue); diff --git a/src/ServiceMonitor/Main.cpp b/src/ServiceMonitor/Main.cpp index 21508ef..bb6b482 100644 --- a/src/ServiceMonitor/Main.cpp +++ b/src/ServiceMonitor/Main.cpp @@ -45,8 +45,8 @@ int __cdecl _tmain(int argc, _TCHAR* argv[]) HRESULT hr = S_OK; Service_Monitor sm = Service_Monitor(); int argIndex; - int serviceTimeout = 20; //default value - in seconds - int appcmdTimeout = 5; //default value - in seconds + DWORD serviceTimeout = 20; //default value - in seconds + DWORD appcmdTimeout = 5; //default value - in seconds bool invalidSyntax = false; int nextPositionalArgument = 1;