ReactOS  0.4.12-dev-36-g472787f
wmisvc.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winsvc.h>
#include <debug.h>
Include dependency graph for wmisvc.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NDEBUG
 

Functions

static VOID UpdateServiceStatus (DWORD dwState)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
VOID WINAPI ServiceMain (DWORD argc, LPTSTR *argv)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"winmgmt"
 
static SERVICE_STATUS_HANDLE ServiceStatusHandle
 
static SERVICE_STATUS ServiceStatus
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 30 of file wmisvc.c.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 31 of file wmisvc.c.

◆ NDEBUG

#define NDEBUG

Definition at line 38 of file wmisvc.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 29 of file wmisvc.c.

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 142 of file wmisvc.c.

145 {
146  switch (fdwReason)
147  {
148  case DLL_PROCESS_ATTACH:
149  DisableThreadLibraryCalls(hinstDLL);
150  break;
151 
152  case DLL_PROCESS_DETACH:
153  break;
154  }
155 
156  return TRUE;
157 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_PROCESS_DETACH
Definition: compat.h:119

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 73 of file wmisvc.c.

Referenced by ServiceMain().

77 {
78  DPRINT1("ServiceControlHandler() called\n");
79 
80  switch (dwControl)
81  {
83  DPRINT1(" SERVICE_CONTROL_STOP received\n");
85  return ERROR_SUCCESS;
86 
88  DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
90  return ERROR_SUCCESS;
91 
93  DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
95  return ERROR_SUCCESS;
96 
98  DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
100  &ServiceStatus);
101  return ERROR_SUCCESS;
102 
104  DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
106  return ERROR_SUCCESS;
107 
108  default :
109  DPRINT1(" Control %lu received\n");
111  }
112 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SERVICE_PAUSED
Definition: winsvc.h:27
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wmisvc.c:51
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wmisvc.c:45
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
static SERVICE_STATUS ServiceStatus
Definition: wmisvc.c:46
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define DPRINT1
Definition: precomp.h:8
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

◆ ServiceMain()

VOID WINAPI ServiceMain ( DWORD  argc,
LPTSTR argv 
)

Definition at line 115 of file wmisvc.c.

116 {
119 
120  DPRINT("ServiceMain() called\n");
121 
124  NULL);
125  if (!ServiceStatusHandle)
126  {
127  DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
128  return;
129  }
130 
132 
133  do
134  {
135  Sleep(1);
136  } while (1);
137 
139 }
static int argc
Definition: ServiceArgs.c:12
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wmisvc.c:51
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static char ** argv
Definition: ServiceArgs.c:11
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wmisvc.c:45
smooth NULL
Definition: ftsmooth.c:416
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wmisvc.c:73
void DPRINT(...)
Definition: polytest.cpp:61
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:773
#define DPRINT1
Definition: precomp.h:8
static WCHAR ServiceName[]
Definition: wmisvc.c:43

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 51 of file wmisvc.c.

Referenced by ServiceControlHandler(), and ServiceMain().

52 {
54  ServiceStatus.dwCurrentState = dwState;
59 
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;
65  else
67 
69  &ServiceStatus);
70 }
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
DWORD dwCheckPoint
Definition: winsvc.h:104
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wmisvc.c:45
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwServiceType
Definition: winsvc.h:99
static SERVICE_STATUS ServiceStatus
Definition: wmisvc.c:46
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23

Variable Documentation

◆ ServiceName

WCHAR ServiceName[] = L"winmgmt"
static

Definition at line 43 of file wmisvc.c.

Referenced by ServiceMain().

◆ ServiceStatus

SERVICE_STATUS ServiceStatus
static

Definition at line 46 of file wmisvc.c.

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle
static

Definition at line 45 of file wmisvc.c.

Referenced by ServiceControlHandler(), ServiceMain(), and UpdateServiceStatus().