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
;
29 /* FUNCTIONS *****************************************************************/
32 UpdateServiceStatus(DWORD dwState
)
34 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
35 ServiceStatus
.dwCurrentState
= dwState
;
36 ServiceStatus
.dwControlsAccepted
= 0;
37 ServiceStatus
.dwWin32ExitCode
= 0;
38 ServiceStatus
.dwServiceSpecificExitCode
= 0;
39 ServiceStatus
.dwCheckPoint
= 0;
41 if (dwState
== SERVICE_START_PENDING
||
42 dwState
== SERVICE_STOP_PENDING
||
43 dwState
== SERVICE_PAUSE_PENDING
||
44 dwState
== SERVICE_CONTINUE_PENDING
)
45 ServiceStatus
.dwWaitHint
= 10000;
47 ServiceStatus
.dwWaitHint
= 0;
49 SetServiceStatus(ServiceStatusHandle
,
54 ServiceControlHandler(DWORD dwControl
,
59 DPRINT1("ServiceControlHandler() called\n");
63 case SERVICE_CONTROL_STOP
:
64 DPRINT1(" SERVICE_CONTROL_STOP received\n");
65 UpdateServiceStatus(SERVICE_STOPPED
);
68 case SERVICE_CONTROL_PAUSE
:
69 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
70 UpdateServiceStatus(SERVICE_PAUSED
);
73 case SERVICE_CONTROL_CONTINUE
:
74 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
75 UpdateServiceStatus(SERVICE_RUNNING
);
78 case SERVICE_CONTROL_INTERROGATE
:
79 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
80 SetServiceStatus(ServiceStatusHandle
,
84 case SERVICE_CONTROL_SHUTDOWN
:
85 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
86 UpdateServiceStatus(SERVICE_STOPPED
);
90 DPRINT1(" Control %lu received\n");
91 return ERROR_CALL_NOT_IMPLEMENTED
;
95 VOID
DealWithDeviceEvent();
98 ServiceMain(DWORD argc
, LPTSTR
*argv
)
100 UNREFERENCED_PARAMETER(argc
);
101 UNREFERENCED_PARAMETER(argv
);
103 DPRINT("ServiceMain() called\n");
105 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
106 ServiceControlHandler
,
108 if (!ServiceStatusHandle
)
110 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
114 DealWithDeviceEvent();
116 UpdateServiceStatus(SERVICE_RUNNING
);
123 UpdateServiceStatus(SERVICE_STOPPED
);
127 DllMain(HINSTANCE hinstDLL
,
133 case DLL_PROCESS_ATTACH
:
134 DisableThreadLibraryCalls(hinstDLL
);
137 case DLL_PROCESS_DETACH
: