ReactOS 0.4.15-dev-7953-g1f49173
wmisvc.c
Go to the documentation of this file.
1/*
2 * ReactOS Services
3 * Copyright (C) 2015 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19/*
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
25 */
26
27/* INCLUDES *****************************************************************/
28
29#define WIN32_NO_STATUS
30#define _INC_WINDOWS
31#define COM_NO_WINDOWS_H
32#include <stdarg.h>
33#include <windef.h>
34#include <winbase.h>
35#include <winreg.h>
36#include <winsvc.h>
37
38#define NDEBUG
39#include <debug.h>
40
41/* GLOBALS ******************************************************************/
42
43static WCHAR ServiceName[] = L"winmgmt";
44
48
49/* FUNCTIONS *****************************************************************/
50
51static VOID
53{
60
61 if (dwState == SERVICE_START_PENDING ||
62 dwState == SERVICE_STOP_PENDING ||
63 dwState == SERVICE_PAUSE_PENDING ||
64 dwState == SERVICE_CONTINUE_PENDING)
66 else
68
69 if (dwState == SERVICE_RUNNING)
71
74}
75
76static DWORD WINAPI
78 DWORD dwEventType,
79 LPVOID lpEventData,
80 LPVOID lpContext)
81{
82 DPRINT1("ServiceControlHandler() called\n");
83
84 switch (dwControl)
85 {
87 DPRINT1(" SERVICE_CONTROL_STOP received\n");
90 return ERROR_SUCCESS;
91
93 DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
95 return ERROR_SUCCESS;
96
98 DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
100 return ERROR_SUCCESS;
101
103 DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
106 return ERROR_SUCCESS;
107
109 DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
112 return ERROR_SUCCESS;
113
114 default :
115 DPRINT1(" Control %lu received\n", dwControl);
117 }
118}
119
122{
125
126 DPRINT("ServiceMain() called\n");
127
130 NULL);
132 {
133 DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
134 return;
135 }
136
138 if (hStopEvent == NULL)
139 {
140 DPRINT1("CreateEvent() failed! (Error %lu)\n", GetLastError());
141 goto done;
142 }
143
145
148
149done:
151}
152
155 DWORD fdwReason,
157{
158 switch (fdwReason)
159 {
162 break;
163
165 break;
166 }
167
168 return TRUE;
169}
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
static int argc
Definition: ServiceArgs.c:12
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
static IN DWORD IN LPVOID lpvReserved
#define argv
Definition: mplay32.c:18
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define DPRINT
Definition: sndvol32.h:71
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCurrentState
Definition: winsvc.h:100
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
static WCHAR ServiceName[]
Definition: wmisvc.c:43
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: wmisvc.c:154
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wmisvc.c:77
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wmisvc.c:52
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wmisvc.c:45
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: wmisvc.c:121
static HANDLE hStopEvent
Definition: wmisvc.c:47
static SERVICE_STATUS ServiceStatus
Definition: wmisvc.c:46
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * LPTSTR
Definition: xmlstorage.h:192