3 * Copyright (C) 2015 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Services
22 * FILE: base/services/wmisvc/wmisvc.c
23 * PURPOSE: WMI service
24 * PROGRAMMER: Pierre Schweitzer
27 /* INCLUDES *****************************************************************/
29 #define WIN32_NO_STATUS
31 #define COM_NO_WINDOWS_H
41 /* GLOBALS ******************************************************************/
43 static WCHAR ServiceName
[] = L
"winmgmt";
45 static SERVICE_STATUS_HANDLE ServiceStatusHandle
;
46 static SERVICE_STATUS ServiceStatus
;
47 static HANDLE ShutdownEvent
;
49 /* FUNCTIONS *****************************************************************/
52 UpdateServiceStatus(DWORD dwState
)
54 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
55 ServiceStatus
.dwCurrentState
= dwState
;
56 ServiceStatus
.dwControlsAccepted
= 0;
57 ServiceStatus
.dwWin32ExitCode
= 0;
58 ServiceStatus
.dwServiceSpecificExitCode
= 0;
59 ServiceStatus
.dwCheckPoint
= 0;
61 if (dwState
== SERVICE_START_PENDING
||
62 dwState
== SERVICE_STOP_PENDING
||
63 dwState
== SERVICE_PAUSE_PENDING
||
64 dwState
== SERVICE_CONTINUE_PENDING
)
65 ServiceStatus
.dwWaitHint
= 10000;
67 ServiceStatus
.dwWaitHint
= 0;
69 SetServiceStatus(ServiceStatusHandle
,
74 ServiceControlHandler(DWORD dwControl
,
79 DPRINT1("ServiceControlHandler() called\n");
83 case SERVICE_CONTROL_STOP
:
84 DPRINT1(" SERVICE_CONTROL_STOP received\n");
85 SetEvent(ShutdownEvent
);
86 UpdateServiceStatus(SERVICE_STOP_PENDING
);
89 case SERVICE_CONTROL_PAUSE
:
90 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
91 UpdateServiceStatus(SERVICE_PAUSED
);
94 case SERVICE_CONTROL_CONTINUE
:
95 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
96 UpdateServiceStatus(SERVICE_RUNNING
);
99 case SERVICE_CONTROL_INTERROGATE
:
100 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
101 SetServiceStatus(ServiceStatusHandle
,
103 return ERROR_SUCCESS
;
105 case SERVICE_CONTROL_SHUTDOWN
:
106 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
107 SetEvent(ShutdownEvent
);
108 UpdateServiceStatus(SERVICE_STOP_PENDING
);
109 return ERROR_SUCCESS
;
112 DPRINT1(" Control %lu received\n");
113 return ERROR_CALL_NOT_IMPLEMENTED
;
118 ServiceMain(DWORD argc
, LPTSTR
*argv
)
120 UNREFERENCED_PARAMETER(argc
);
121 UNREFERENCED_PARAMETER(argv
);
123 DPRINT("ServiceMain() called\n");
125 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
126 ServiceControlHandler
,
128 if (!ServiceStatusHandle
)
130 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
134 ShutdownEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
136 UpdateServiceStatus(SERVICE_RUNNING
);
138 WaitForSingleObject(ShutdownEvent
, INFINITE
);
139 CloseHandle(ShutdownEvent
);
141 UpdateServiceStatus(SERVICE_STOPPED
);
145 DllMain(HINSTANCE hinstDLL
,
151 case DLL_PROCESS_ATTACH
:
152 DisableThreadLibraryCalls(hinstDLL
);
155 case DLL_PROCESS_DETACH
: