ServiceInstance.h
Go to the documentation of this file.
1 #pragma once
2 
3 #define SERVICE_CONTROL_START 0
4 
5 namespace AppSecInc
6 {
7  namespace Service
8  {
11  {
12  private:
13  SC_HANDLE m_h;
14  public:
16  virtual ~ServiceInstance();
18  void Open(const ServiceManager& scm, const std::wstring& name, DWORD access = SERVICE_ALL_ACCESS);
20  void Create(const ServiceManager& scm, const ServiceCreateInfo& info);
22  void Delete();
24  void Close();
26  bool IsOpen() const { return m_h != NULL; }
28  SC_HANDLE GetHandle() const { return m_h; }
30  void GetServiceProcessStatus(LPSERVICE_STATUS_PROCESS) const;
32  void Control(DWORD control);
34  void Stop();
36  void Start();
38  void Restart();
40  void Pause();
42  void Continue();
44  DWORD GetServiceState() const;
46  bool IsStarted() const { return (GetServiceState() == SERVICE_RUNNING); }
48  bool IsStopped() const { return (GetServiceState() == SERVICE_STOPPED); }
50  bool IsPaused() const { return (GetServiceState() == SERVICE_PAUSED); }
52  // \param sleep number of milliseconds to sleep between checks
53  // \param timeout timeout to wait
54  // \return true if operation successful, false on timeout
55  bool Wait(DWORD timeout = INFINITE) const;
57  ServiceConfig GetConfig() const;
59  std::wstring GetDescription() const;
60  };
61  }
62 }
63 
bool Wait(DWORD timeout=INFINITE) const
wait for a transition to complete while the service is pausing, starting, stopping, etc.
Definition: ServiceInstance.cpp:137
DWORD GetServiceState() const
return the service state
Definition: ServiceInstance.cpp:130
void Control(DWORD control)
control a service
Definition: ServiceInstance.cpp:86
service creation information
Definition: ServiceCreateInfo.h:8
bool IsStopped() const
returns true if the service is stopped
Definition: ServiceInstance.h:48
void Pause()
pause a service
Definition: ServiceInstance.cpp:120
void Close()
close a previously opened service object
Definition: ServiceInstance.cpp:19
void Delete()
delete the service
Definition: ServiceInstance.cpp:39
ServiceConfig GetConfig() const
get service configuration
Definition: ServiceInstance.cpp:185
void Start()
start a service
Definition: ServiceInstance.cpp:109
std::wstring GetDescription() const
get service description
Definition: ServiceInstance.cpp:161
void GetServiceProcessStatus(LPSERVICE_STATUS_PROCESS) const
return process information
Definition: ServiceInstance.cpp:76
virtual ~ServiceInstance()
Definition: ServiceInstance.cpp:11
void Create(const ServiceManager &scm, const ServiceCreateInfo &info)
create a new service
Definition: ServiceInstance.cpp:50
SC_HANDLE GetHandle() const
return the service handle
Definition: ServiceInstance.h:28
void Continue()
continue (resume) a service
Definition: ServiceInstance.cpp:125
Service manager.
Definition: ServiceManager.h:8
void Stop()
stop a service
Definition: ServiceInstance.cpp:104
void Open(const ServiceManager &scm, const std::wstring &name, DWORD access=SERVICE_ALL_ACCESS)
open the service instance object
Definition: ServiceInstance.cpp:27
service configuration
Definition: ServiceConfig.h:8
ServiceInstance()
Definition: ServiceInstance.cpp:6
a service instance
Definition: ServiceInstance.h:10
void Restart()
restart a service
Definition: ServiceInstance.cpp:114
bool IsPaused() const
returns true if the service is paused
Definition: ServiceInstance.h:50
bool IsOpen() const
returns true if service is already open
Definition: ServiceInstance.h:26
bool IsStarted() const
returns true if the service is started
Definition: ServiceInstance.h:46


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com