ReactOS  0.4.14-dev-115-g4576127
stop.c File Reference
#include "precomp.h"
Include dependency graph for stop.c:

Go to the source code of this file.

Macros

#define MAX_WAIT_TIME   30000
 

Functions

BOOL DoStopService (_In_z_ LPWSTR ServiceName, _In_opt_ HANDLE hProgress)
 

Macro Definition Documentation

◆ MAX_WAIT_TIME

#define MAX_WAIT_TIME   30000

Definition at line 12 of file stop.c.

Function Documentation

◆ DoStopService()

BOOL DoStopService ( _In_z_ LPWSTR  ServiceName,
_In_opt_ HANDLE  hProgress 
)

Definition at line 15 of file stop.c.

17 {
18  SC_HANDLE hSCManager;
19  SC_HANDLE hService;
21  DWORD BytesNeeded;
23  DWORD WaitTime;
24  DWORD Timeout;
25  BOOL bRet = FALSE;
26 
27 
29  NULL,
31  if (!hSCManager) return FALSE;
32 
33  hService = OpenServiceW(hSCManager,
36  if (!hService)
37  {
39  return FALSE;
40  }
41 
42  if (hProgress)
43  {
44  /* Increment the progress bar */
46  }
47 
48  /* Set the start and max wait times */
51 
52  /* Send the service the stop code */
53  if (ControlService(hService,
56  {
57  if (hProgress)
58  {
59  /* Increment the progress bar */
61  }
62 
64  {
65  int i;
66  /* Fixup the wait time */
67  WaitTime = ServiceStatus.dwWaitHint / 10;
68 
69  if (WaitTime < 1000) WaitTime = 1000;
70  else if (WaitTime > 10000) WaitTime = 10000;
71 
72  /* We don't wanna wait for up to 10 secs without incrementing */
73  for (i = WaitTime / 1000; i > 0; i--)
74  {
75  Sleep(1000);
76  if (hProgress)
77  {
78  /* Increment the progress bar */
80  }
81  }
82 
83  if (QueryServiceStatusEx(hService,
86  sizeof(SERVICE_STATUS_PROCESS),
87  &BytesNeeded))
88  {
89  /* Have we exceeded our wait time? */
90  if (GetTickCount() - StartTime > Timeout)
91  {
92  /* Yep, give up */
93  break;
94  }
95  }
96  }
97 
98  /* If the service is stopped, return TRUE */
100  {
101  bRet = TRUE;
102  }
103  }
104 
105  CloseServiceHandle(hService);
106 
108 
109  return bRet;
110 }
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
DWORD dwCurrentState
Definition: winsvc.h:100
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
static SERVICE_STATUS ServiceStatus
Definition: dcomlaunch.c:27
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2830
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SERVICE_STOPPED
Definition: winsvc.h:21
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
LPTSTR ServiceName
Definition: ServiceMain.c:15
DWORD dwWaitHint
Definition: winsvc.h:105
unsigned long DWORD
Definition: ntddk_ex.h:95
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
SC_HANDLE hSCManager
Definition: sc.c:12
VOID IncrementProgressBar(HANDLE hProgress, UINT NewPos)
Definition: progress.c:288
static ULONG Timeout
Definition: ping.c:61
#define MAX_WAIT_TIME
Definition: stop.c:12
#define DEFAULT_STEP
Definition: precomp.h:108
#define SERVICE_STOP
Definition: winsvc.h:58
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36