PSERVICE_GROUP Group = Service->lpGroup;
DWORD dwError = ERROR_SUCCESS;
LPCWSTR ErrorLogStrings[2];
+ WCHAR szErrorBuffer[32];
DPRINT("ScmStartService() called\n");
{
if (Service->dwErrorControl != SERVICE_ERROR_IGNORE)
{
+ /* Log a failed service start */
+ swprintf(szErrorBuffer, L"%lu", dwError);
ErrorLogStrings[0] = Service->lpServiceName;
- ErrorLogStrings[1] = L"Test";
+ ErrorLogStrings[1] = szErrorBuffer;
ScmLogError(EVENT_SERVICE_START_FAILED,
2,
ErrorLogStrings);
LPSERVICE_STATUS lpServiceStatus)
{
PSERVICE lpService;
+ DWORD dwPreviousState;
+ LPCWSTR lpErrorStrings[2];
+ WCHAR szErrorBuffer[32];
DPRINT("RSetServiceStatus() called\n");
DPRINT("hServiceStatus = %p\n", hServiceStatus);
/* Lock the service database exclusively */
ScmLockDatabaseExclusive();
+ /* Save the current service state */
+ dwPreviousState = lpService->Status.dwCurrentState;
+
RtlCopyMemory(&lpService->Status,
lpServiceStatus,
sizeof(SERVICE_STATUS));
/* Unlock the service database */
ScmUnlockDatabase();
+ /* Log a failed service stop */
+ if ((lpServiceStatus->dwCurrentState == SERVICE_STOPPED) &&
+ (dwPreviousState != SERVICE_STOPPED))
+ {
+ if (lpServiceStatus->dwWin32ExitCode != ERROR_SUCCESS)
+ {
+ swprintf(szErrorBuffer, L"%lu", lpServiceStatus->dwWin32ExitCode);
+ lpErrorStrings[0] = lpService->lpDisplayName;
+ lpErrorStrings[1] = szErrorBuffer;
+
+ ScmLogError(EVENT_SERVICE_EXIT_FAILED,
+ 2,
+ lpErrorStrings);
+ }
+ }
+
DPRINT("Set %S to %lu\n", lpService->lpDisplayName, lpService->Status.dwCurrentState);
DPRINT("RSetServiceStatus() done\n");