-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathWin32_Service.hpp
181 lines (132 loc) · 4.02 KB
/
Win32_Service.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
////////////////////////////////////////////////////////////////////////////////
//! \file Win32_Service.hpp
//! \brief The Win32_Service class declaration.
//! \author Chris Oldwood
// Check for previous inclusion
#ifndef WMI_WIN32_SERVICE_HPP
#define WMI_WIN32_SERVICE_HPP
#if _MSC_VER > 1000
#pragma once
#endif
#include "TypedObject.hpp"
namespace WMI
{
////////////////////////////////////////////////////////////////////////////////
//! The C++ facade for the Win32_Service WMI class.
class Win32_Service : public TypedObject<Win32_Service>
{
public:
//! Construction from the underlying COM object and connection.
Win32_Service(IWbemClassObjectPtr object, const Connection& connection);
//! Destructor.
virtual ~Win32_Service();
//
// WMI typed properties.
//
//! The description of the service.
tstring Description() const;
//! The display name of the service.
tstring DisplayName() const;
//! The unique name of the service.
tstring Name() const;
//! The type of the service.
tstring ServiceType() const;
//! The start mode of the service.
tstring StartMode() const;
//! The current state of the service.
tstring State() const;
//
// WMI property helpers.
//
//! Is the service disabled?
bool IsDisabled() const;
//! Is the service started manually?
bool IsManual() const;
//! Does the service start automatically?
bool IsAutomatic() const;
//! Is the service running?
bool IsStopped() const;
//! Is the service running?
bool IsRunning() const;
//
// WMI methods.
//
//! Start the service.
uint32 StartService();
//! Stop the service.
uint32 StopService();
//
// Constants.
//
//! The WMI class name this type mirrors.
static const tchar* WMI_CLASS_NAME;
};
////////////////////////////////////////////////////////////////////////////////
//! The description of the service.
inline tstring Win32_Service::Description() const
{
return getProperty<tstring>(TXT("Description"));
}
////////////////////////////////////////////////////////////////////////////////
//! The display name of the service.
inline tstring Win32_Service::DisplayName() const
{
return getProperty<tstring>(TXT("DisplayName"));
}
////////////////////////////////////////////////////////////////////////////////
//! The unique name of the service.
inline tstring Win32_Service::Name() const
{
return getProperty<tstring>(TXT("Name"));
}
////////////////////////////////////////////////////////////////////////////////
//! The type of the service.
inline tstring Win32_Service::ServiceType() const
{
return getProperty<tstring>(TXT("ServiceType"));
}
////////////////////////////////////////////////////////////////////////////////
//! The start mode of the service.
inline tstring Win32_Service::StartMode() const
{
return getProperty<tstring>(TXT("StartMode"));
}
////////////////////////////////////////////////////////////////////////////////
//! The current state of the service.
inline tstring Win32_Service::State() const
{
return getProperty<tstring>(TXT("State"));
}
////////////////////////////////////////////////////////////////////////////////
//! Is the service disabled?
inline bool Win32_Service::IsDisabled() const
{
return (StartMode() == TXT("Disabled"));
}
////////////////////////////////////////////////////////////////////////////////
//! Is the service started manually?
inline bool Win32_Service::IsManual() const
{
return (StartMode() == TXT("Manual"));
}
////////////////////////////////////////////////////////////////////////////////
//! Does the service start automatically?
inline bool Win32_Service::IsAutomatic() const
{
return (StartMode() == TXT("Auto"));
}
////////////////////////////////////////////////////////////////////////////////
//! Is the service running?
inline bool Win32_Service::IsStopped() const
{
return (State() == TXT("Stopped"));
}
////////////////////////////////////////////////////////////////////////////////
//! Is the service running?
inline bool Win32_Service::IsRunning() const
{
return (State() == TXT("Running"));
}
//namespace WMI
}
#endif // WMI_WIN32_SERVICE_HPP