2 * PROJECT: ReactOS Update Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Automatic Updates service stub.
5 * Stub is required for some application at the installation phase.
6 * COPYRIGHT: Copyright 2018 Denis Malikov (filedem@gmail.com)
11 /* GLOBALS ******************************************************************/
13 static WCHAR ServiceName
[] = L
"wuauserv";
15 static SERVICE_STATUS_HANDLE ServiceStatusHandle
;
16 static SERVICE_STATUS ServiceStatus
;
18 static HANDLE exitEvent
= NULL
;
20 /* FUNCTIONS *****************************************************************/
23 UpdateServiceStatus(DWORD dwState
)
25 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
26 ServiceStatus
.dwCurrentState
= dwState
;
27 ServiceStatus
.dwControlsAccepted
= 0;
28 ServiceStatus
.dwWin32ExitCode
= 0;
29 ServiceStatus
.dwServiceSpecificExitCode
= 0;
30 ServiceStatus
.dwCheckPoint
= 0;
32 if (dwState
== SERVICE_START_PENDING
||
33 dwState
== SERVICE_STOP_PENDING
||
34 dwState
== SERVICE_PAUSE_PENDING
||
35 dwState
== SERVICE_CONTINUE_PENDING
)
36 ServiceStatus
.dwWaitHint
= 1000;
38 ServiceStatus
.dwWaitHint
= 0;
40 SetServiceStatus(ServiceStatusHandle
,
42 DPRINT1("WU UpdateServiceStatus() called\n");
46 ServiceControlHandler(DWORD dwControl
,
53 case SERVICE_CONTROL_STOP
:
54 DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_STOP received\n");
55 UpdateServiceStatus(SERVICE_STOPPED
);
59 case SERVICE_CONTROL_PAUSE
:
60 DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_PAUSE received\n");
61 UpdateServiceStatus(SERVICE_PAUSED
);
64 case SERVICE_CONTROL_CONTINUE
:
65 DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_CONTINUE received\n");
66 UpdateServiceStatus(SERVICE_RUNNING
);
69 case SERVICE_CONTROL_INTERROGATE
:
70 DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_INTERROGATE received\n");
71 SetServiceStatus(ServiceStatusHandle
,
75 case SERVICE_CONTROL_SHUTDOWN
:
76 DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_SHUTDOWN received\n");
77 UpdateServiceStatus(SERVICE_STOPPED
);
81 DPRINT1("WU ServiceControlHandler() Control %lu received\n");
82 return ERROR_CALL_NOT_IMPLEMENTED
;
87 ServiceMain(DWORD argc
, LPTSTR
*argv
)
89 UNREFERENCED_PARAMETER(argc
);
90 UNREFERENCED_PARAMETER(argv
);
92 DPRINT("WU ServiceMain() called\n");
94 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
95 ServiceControlHandler
,
97 if (!ServiceStatusHandle
)
99 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
103 UpdateServiceStatus(SERVICE_RUNNING
);
105 exitEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
106 WaitForSingleObject(exitEvent
, INFINITE
);
107 CloseHandle(exitEvent
);
109 UpdateServiceStatus(SERVICE_STOPPED
);
113 DllMain(HINSTANCE hinstDLL
,
119 case DLL_PROCESS_ATTACH
:
120 DisableThreadLibraryCalls(hinstDLL
);
123 case DLL_PROCESS_DETACH
: