libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
ServiceManipulation.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
20 
21 // For the Service Manager functions. (NT only.)
22 #include<winsvc.h>
23 
24 namespace jmmcg { namespace NTUtils {
25 
26  class win_exception;
27 
28  class AFX_EXT_CLASS ServiceManipulation : virtual protected LoadLibraryWrapper {
29  public:
31 
32  __stdcall ServiceManipulation(const TCHAR * const machine=NULL);
33  __stdcall ~ServiceManipulation(void);
34 
35  void __fastcall OpenService(const TCHAR * const service_name, const DWORD access);
36  inline unsigned long __fastcall ControlService(const DWORD dwControl,SERVICE_STATUS &status) noexcept(true) {if (!(*pControlService)(curr_service,dwControl,&status)) {return ::GetLastError();};return NULL;};
37  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;};
38 
39  private:
40  typedef /*WINADVAPI*/ BOOL (WINAPI * const CloseServiceHandleType)(SC_HANDLE hSCObject);
44 
49  SC_HANDLE scm;
51  const TCHAR *curr_service_name;
52 
53  // Stop any compiler silliness...
55  inline ServiceManipulation & __fastcall operator=(const ServiceManipulation &);
56  };
57 
58 } }