root/experimental/NT-based/NTSpecific/ServiceManipulation.hpp

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ControlService
  2. StartService

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/experimental/NT-based/NTSpecific/ServiceManipulation.hpp 2055 2017-05-13 19:35:47Z jmmcg $
   3 ** 
   4 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19 */
  20 
  21 #include "LoadLibraryWrapper.hpp"
  22 
  23 // For the Service Manager functions. (NT only.)
  24 #include<winsvc.h>
  25 
  26 namespace jmmcg { namespace NTUtils {
  27 
  28         class win_exception;
  29 
  30         class AFX_EXT_CLASS ServiceManipulation : virtual protected LoadLibraryWrapper {
  31         public:
  32                 typedef win_exception exception_type;
  33 
  34                 __stdcall ServiceManipulation(const TCHAR * const machine=NULL);
  35                 __stdcall ~ServiceManipulation(void);
  36 
  37                 void __fastcall OpenService(const TCHAR * const service_name, const DWORD access);
  38                 inline unsigned long __fastcall ControlService(const DWORD dwControl,SERVICE_STATUS &status) noexcept(true) {if (!(*pControlService)(curr_service,dwControl,&status)) {return ::GetLastError();};return NULL;};
  39                 inline unsigned long __fastcall StartService(const DWORD num_args,const TCHAR **args) noexcept(true) {if (!(*pStartService)(curr_service,num_args,args)) {return ::GetLastError();};return NULL;};
  40 
  41         private:
  42                 typedef /*WINADVAPI*/ BOOL (WINAPI * const CloseServiceHandleType)(SC_HANDLE hSCObject);
  43                 typedef /*WINADVAPI*/ SC_HANDLE (WINAPI * const OpenServiceType)(SC_HANDLE hSCManager,LPCTSTR lpServiceName,DWORD dwDesiredAccess);
  44                 typedef /*WINADVAPI*/ BOOL (WINAPI * const ControlServiceType)(SC_HANDLE hService,DWORD dwControl,LPSERVICE_STATUS lpServiceStatus);
  45                 typedef /*WINADVAPI*/ BOOL (WINAPI * const StartServiceType)(SC_HANDLE hService,DWORD dwNumServiceArgs,LPCTSTR *lpServiceArgVectors);
  46 
  47                 const CloseServiceHandleType pCloseServiceHandle;
  48                 const OpenServiceType pOpenService;
  49                 const ControlServiceType pControlService;
  50                 const StartServiceType pStartService;
  51                 SC_HANDLE scm;
  52                 SC_HANDLE curr_service;
  53                 const TCHAR *curr_service_name;
  54 
  55                 // Stop any compiler silliness...
  56                 inline ServiceManipulation(const ServiceManipulation &);
  57                 inline ServiceManipulation & __fastcall operator=(const ServiceManipulation &);
  58         };
  59 
  60 } }

/* [<][>][^][v][top][bottom][index][help] */