2 * PROJECT: ReactOS RPC Subsystem Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: DCOMLAUNCH service
5 * COPYRIGHT: Copyright 2019 Pierre Schweitzer
8 /* INCLUDES *****************************************************************/
10 #define WIN32_NO_STATUS
12 #define COM_NO_WINDOWS_H
22 /* GLOBALS ******************************************************************/
24 static WCHAR ServiceName
[] = L
"dcomlaunch";
26 static SERVICE_STATUS_HANDLE ServiceStatusHandle
;
27 static SERVICE_STATUS ServiceStatus
;
28 static HANDLE ShutdownEvent
;
30 /* FUNCTIONS *****************************************************************/
33 UpdateServiceStatus(DWORD dwState
)
35 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
36 ServiceStatus
.dwCurrentState
= dwState
;
37 ServiceStatus
.dwControlsAccepted
= 0;
38 ServiceStatus
.dwWin32ExitCode
= 0;
39 ServiceStatus
.dwServiceSpecificExitCode
= 0;
40 ServiceStatus
.dwCheckPoint
= 0;
42 if (dwState
== SERVICE_START_PENDING
||
43 dwState
== SERVICE_STOP_PENDING
||
44 dwState
== SERVICE_PAUSE_PENDING
||
45 dwState
== SERVICE_CONTINUE_PENDING
)
46 ServiceStatus
.dwWaitHint
= 10000;
48 ServiceStatus
.dwWaitHint
= 0;
50 SetServiceStatus(ServiceStatusHandle
,
55 ServiceControlHandler(DWORD dwControl
,
60 DPRINT1("ServiceControlHandler() called\n");
64 case SERVICE_CONTROL_STOP
:
65 DPRINT1(" SERVICE_CONTROL_STOP received\n");
66 SetEvent(ShutdownEvent
);
67 UpdateServiceStatus(SERVICE_STOP_PENDING
);
70 case SERVICE_CONTROL_PAUSE
:
71 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
72 UpdateServiceStatus(SERVICE_PAUSED
);
75 case SERVICE_CONTROL_CONTINUE
:
76 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
77 UpdateServiceStatus(SERVICE_RUNNING
);
80 case SERVICE_CONTROL_INTERROGATE
:
81 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
82 SetServiceStatus(ServiceStatusHandle
,
86 case SERVICE_CONTROL_SHUTDOWN
:
87 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
88 SetEvent(ShutdownEvent
);
89 UpdateServiceStatus(SERVICE_STOP_PENDING
);
93 DPRINT1(" Control %lu received\n", dwControl
);
94 return ERROR_CALL_NOT_IMPLEMENTED
;
98 VOID
DealWithDeviceEvent();
101 ServiceMain(DWORD argc
, LPTSTR
*argv
)
103 UNREFERENCED_PARAMETER(argc
);
104 UNREFERENCED_PARAMETER(argv
);
106 DPRINT("ServiceMain() called\n");
108 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
109 ServiceControlHandler
,
111 if (!ServiceStatusHandle
)
113 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
117 ShutdownEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
119 DealWithDeviceEvent();
121 UpdateServiceStatus(SERVICE_RUNNING
);
123 WaitForSingleObject(ShutdownEvent
, INFINITE
);
124 CloseHandle(ShutdownEvent
);
126 UpdateServiceStatus(SERVICE_STOPPED
);
130 DllMain(HINSTANCE hinstDLL
,
136 case DLL_PROCESS_ATTACH
:
137 DisableThreadLibraryCalls(hinstDLL
);
140 case DLL_PROCESS_DETACH
: