On Windows 2000, StartService() and ControlService() return
ERROR_IO_PENDING immediately. Later versions of Windows have a
builtin timeout before they will return that error.
As far as we're concerned, ERROR_IO_PENDING indicates that the service
control was sent successfully so we simply override the error and
return success.
If NSSM's service management functionality is ever expanded we can take
the time to handle service controls in a more robust way.
CloseHandle(service_handle);\r
CloseServiceHandle(services);\r
\r
CloseHandle(service_handle);\r
CloseServiceHandle(services);\r
\r
+ if (error == ERROR_IO_PENDING) {\r
+ /*\r
+ Older versions of Windows return immediately with ERROR_IO_PENDING\r
+ indicate that the operation is still in progress. Newer versions\r
+ will return it if there really is a delay. As far as we're\r
+ concerned the operation is a success. We don't claim to offer a\r
+ fully-feature service control method; it's just a quick 'n' dirty\r
+ interface.\r
+\r
+ In the future we may identify and handle this situation properly.\r
+ */\r
+ ret = 1;\r
+ error = ERROR_SUCCESS;\r
+ }\r
+\r
if (ret) {\r
_tprintf(_T("%s: %s"), canonical_name, error_string(error));\r
return 0;\r
if (ret) {\r
_tprintf(_T("%s: %s"), canonical_name, error_string(error));\r
return 0;\r
CloseHandle(service_handle);\r
CloseServiceHandle(services);\r
\r
CloseHandle(service_handle);\r
CloseServiceHandle(services);\r
\r
+ if (error == ERROR_IO_PENDING) {\r
+ ret = 1;\r
+ error = ERROR_SUCCESS;\r
+ }\r
+\r
if (ret) {\r
_tprintf(_T("%s: %s"), canonical_name, error_string(error));\r
return 0;\r
if (ret) {\r
_tprintf(_T("%s: %s"), canonical_name, error_string(error));\r
return 0;\r