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
;
48 /* FUNCTIONS *****************************************************************/
51 UpdateServiceStatus(DWORD dwState
)
53 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
54 ServiceStatus
.dwCurrentState
= dwState
;
55 ServiceStatus
.dwControlsAccepted
= 0;
56 ServiceStatus
.dwWin32ExitCode
= 0;
57 ServiceStatus
.dwServiceSpecificExitCode
= 0;
58 ServiceStatus
.dwCheckPoint
= 0;
60 if (dwState
== SERVICE_START_PENDING
||
61 dwState
== SERVICE_STOP_PENDING
||
62 dwState
== SERVICE_PAUSE_PENDING
||
63 dwState
== SERVICE_CONTINUE_PENDING
)
64 ServiceStatus
.dwWaitHint
= 10000;
66 ServiceStatus
.dwWaitHint
= 0;
68 SetServiceStatus(ServiceStatusHandle
,
73 ServiceControlHandler(DWORD dwControl
,
78 DPRINT1("ServiceControlHandler() called\n");
82 case SERVICE_CONTROL_STOP
:
83 DPRINT1(" SERVICE_CONTROL_STOP received\n");
84 UpdateServiceStatus(SERVICE_STOPPED
);
87 case SERVICE_CONTROL_PAUSE
:
88 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
89 UpdateServiceStatus(SERVICE_PAUSED
);
92 case SERVICE_CONTROL_CONTINUE
:
93 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
94 UpdateServiceStatus(SERVICE_RUNNING
);
97 case SERVICE_CONTROL_INTERROGATE
:
98 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
99 SetServiceStatus(ServiceStatusHandle
,
101 return ERROR_SUCCESS
;
103 case SERVICE_CONTROL_SHUTDOWN
:
104 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
105 UpdateServiceStatus(SERVICE_STOPPED
);
106 return ERROR_SUCCESS
;
109 DPRINT1(" Control %lu received\n");
110 return ERROR_CALL_NOT_IMPLEMENTED
;
115 ServiceMain(DWORD argc
, LPTSTR
*argv
)
117 UNREFERENCED_PARAMETER(argc
);
118 UNREFERENCED_PARAMETER(argv
);
120 DPRINT("ServiceMain() called\n");
122 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
123 ServiceControlHandler
,
125 if (!ServiceStatusHandle
)
127 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
131 UpdateServiceStatus(SERVICE_RUNNING
);
138 UpdateServiceStatus(SERVICE_STOPPED
);
142 DllMain(HINSTANCE hinstDLL
,
148 case DLL_PROCESS_ATTACH
:
149 DisableThreadLibraryCalls(hinstDLL
);
152 case DLL_PROCESS_DETACH
: