windows_snapshot/operating_system/services.rs
1//! The Services subcategory groups classes that represent services and base services.
2//!
3//! | Class | Description |
4//! |-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
5//! | [**`Win32\_Servic`e**](win32-service) | Instance class<br/> Represents a service on a computer system running Windows.<br/> |
6
7use crate::update;
8use serde::{Deserialize, Serialize};
9use std::time::SystemTime;
10use wmi::{COMLibrary, WMIConnection, WMIDateTime};
11
12/// Represents the state of Windows Drivers
13#[derive(Deserialize, Serialize, Debug, Clone)]
14pub struct Services {
15 /// Sequence of Drivers based on when they were loaded in chronological order
16 pub services: Vec<Win32_Service>,
17 /// When was the record last updated
18 pub last_updated: SystemTime,
19}
20
21update!(Services, services);
22
23/// The `Win32_Service` WMI class represents a process on an operating system.
24///
25/// <https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-service>
26#[derive(Default, Deserialize, Serialize, Debug, Clone)]
27#[allow(non_snake_case)]
28#[allow(non_camel_case_types)]
29pub struct Win32_Service {
30 /// Indicates whether the service can be paused.
31 pub AcceptPause: Option<bool>,
32 /// Indicates whether the service can be stopped.
33 pub AcceptStop: Option<bool>,
34 /// Short description of the service — a one-line string.
35 pub Caption: Option<String>,
36 /// Value that the service increments periodically to report its progress during a long start,
37 /// stop, pause, or continue operation. For example, the service increments this value as it
38 /// completes each step of its initialization when it is starting up. The user interface program
39 /// that invokes the operation on the service uses this value to track the progress of the
40 /// service during a lengthy operation. This value is not valid and should be zero when the
41 /// service does not have a start, stop, pause, or continue operation pending.
42 pub CheckPoint: Option<u32>,
43 /// Name of the first concrete class to appear in the inheritance chain used in the creation of
44 /// an instance. When used with the other key properties of the class, this property allows all
45 /// instances of this class and its subclasses to be uniquely identified.
46 pub CreationClassName: Option<String>,
47 /// If True, the service is started after other auto-start services are started plus a short
48 /// delay.
49 ///
50 /// Windows Server 2012 R2, Windows 8.1, Windows Server 2012, Windows 8, Windows Server 2008 R2,
51 /// Windows 7, Windows Server 2008 and Windows Vista: This property is not supported before
52 /// Windows Server 2016 and Windows 10.
53 pub DelayedAutoStart: Option<bool>,
54 /// Description of the object.
55 pub Description: Option<String>,
56 /// Indicates whether the service can create or communicate with windows on the desktop, and
57 /// thus interact in some way with a user. Interactive services must run under the Local System
58 /// account. Most services are not interactive; that is, they do not communicate with the user
59 /// in any way.
60 pub DesktopInteract: Option<bool>,
61 /// Name of the service as viewed in the Services snap-in. This string has a maximum length of
62 /// 256 characters. Note that the display name and the service name (which is stored in the
63 /// registry) are not always the same. For example, the DHCP Client service has the service
64 /// name Dhcp but the display name DHCP Client. The name is case-preserved in the Service
65 /// Control Manager. However, DisplayName comparisons are always case-insensitive.
66 ///
67 /// Constraint: Accepts the same value as the Name property.
68 ///
69 /// Example: "Atdisk"
70 pub DisplayName: Option<String>,
71 /// Severity of the error if this service fails to start during startup. The value indicates
72 /// the action taken by the startup program if failure occurs. All errors are logged by the
73 /// computer system.
74 ///
75 /// - Ignore ("Ignore"): User is not notified.
76 /// - Normal ("Normal"): User is notified. Usually this will be a message box display notifying the user of the problem.
77 /// - Severe ("Severe"): System is restarted with the last-known-good configuration.
78 /// - Critical ("Critical"): System attempts to restart with a good configuration. If the service fails to start a second time, startup fails.
79 /// - Unknown ("Unknown"): Severity of the error is unknown.
80 pub ErrorControl: Option<String>,
81 /// Windows error code that defines errors encountered in starting or stopping the service.
82 /// This property is set to ERROR_SERVICE_SPECIFIC_ERROR (1066) when the error is unique to the
83 /// service represented by this class, and information about the error is available in the
84 /// ServiceSpecificExitCode property. The service sets this value to NO_ERROR when running, and
85 /// again upon normal termination.
86 pub ExitCode: Option<u32>,
87 /// Date object is installed. This property does not require a value to indicate that the object
88 /// is installed.
89 pub InstallDate: Option<WMIDateTime>,
90 /// Unique identifier of the service that provides an indication of the functionality that is
91 /// managed. This functionality is described in the Description property of the object.
92 pub Name: Option<String>,
93 /// Fully qualified path to the service binary file that implements the service.
94 ///
95 /// Example: "\SystemRoot\System32\drivers\afd.sys"
96 pub PathName: Option<String>,
97 /// Process identifier of the service.
98 ///
99 /// Example: 324
100 pub ProcessId: Option<u32>,
101 /// Service-specific error code for errors that occur while the service is either starting or
102 /// stopping. The exit codes are defined by the service represented by this class. This value
103 /// is only set when the ExitCode property value is ERROR_SERVICE_SPECIFIC_ERROR (1066).
104 pub ServiceSpecificExitCode: Option<u32>,
105 /// Type of service provided to calling processes.
106 ///
107 /// The values are:
108 ///
109 /// - Kernel Driver ("Kernel Driver")
110 /// - File System Driver ("File System Driver")
111 /// - Adapter ("Adapter")
112 /// - Recognizer Driver ("Recognizer Driver")
113 /// - Own Process ("Own Process")
114 /// - Share Process ("Share Process")
115 /// - Interactive Process ("Interactive Process")
116 pub ServiceType: Option<String>,
117 /// Indicates whether or not the service is started.
118 pub Started: Option<bool>,
119 /// Start mode of the Windows base service.
120 ///
121 /// - Boot ("Boot"): Device driver started by the operating system loader (valid only for driver services).
122 /// - System ("System"): Device driver started by the operating system initialization process. This value is valid only for driver services.
123 /// - Auto ("Auto"): Service to be started automatically by the service control manager during system startup. Auto services are started even if a user does not log on.
124 /// - Manual ("Manual"): Service to be started by the Service Control Manager when a process calls the StartService method. These services do not start unless a user logs on and starts them.
125 /// - Disabled ("Disabled"): Service that cannot be started until its StartMode is changed to either Auto or Manual.
126 pub StartMode: Option<String>,
127 /// Account name under which a service runs. Depending on the service type, the account name
128 /// may be in the form of "DomainName\Username" or UPN format ("Username@DomainName"). The
129 /// service process is logged by using one of these two forms when it runs. If the account
130 /// belongs to the built-in domain, then ".\Username" can be specified. For kernel or
131 /// system-level drivers, StartName contains the driver object name (that is, "\FileSystem\Rdr"
132 /// or "\Driver\Xns") which the I/O system uses to load the device driver. Additionally, if NULL
133 /// is specified, the driver runs with a default object name created by the I/O system based on
134 /// the service name.
135 ///
136 /// Example: "DWDOM\Admin"
137 pub StartName: Option<String>,
138 /// Current state of the base service.
139 ///
140 /// The values are:
141 ///
142 /// - Stopped ("Stopped")
143 /// - Start Pending ("Start Pending")
144 /// - Stop Pending ("Stop Pending")
145 /// - Running ("Running")
146 /// - Continue Pending ("Continue Pending")
147 /// - Pause Pending ("Pause Pending")
148 /// - Paused ("Paused")
149 /// - Unknown ("Unknown")
150 pub State: Option<String>,
151 /// Current status of the object. Various operational and nonoperational statuses can be
152 /// defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element,
153 /// such as a SMART-enabled hard disk drive, may be functioning properly but predicting a
154 /// failure in the near future). Nonoperational statuses include: "Error", "Starting",
155 /// "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering
156 /// of a disk, reload of a user permissions list, or other administrative work. Not all such
157 /// work is online, yet the managed element is neither "OK" nor in one of the other states.
158 ///
159 /// The values are:
160 ///
161 /// - OK ("OK")
162 /// - Error ("Error")
163 /// - Degraded ("Degraded")
164 /// - Unknown ("Unknown")
165 /// - Pred Fail ("Pred Fail")
166 /// - Starting ("Starting")
167 /// - Stopping ("Stopping")
168 /// - Service ("Service")
169 /// - Stressed ("Stressed")
170 /// - NonRecover ("NonRecover")
171 /// - No Contact ("No Contact")
172 /// - Lost Comm ("Lost Comm")
173 pub Status: Option<String>,
174 /// Type name of the system that hosts this service.
175 pub SystemCreationClassName: Option<String>,
176 /// Name of the system that hosts this service.
177 pub SystemName: Option<String>,
178 /// Unique tag value for this service in the group. A value of 0 (zero) indicates that the
179 /// service does not have a tag. A tag can be used to order service startup within a load order
180 /// group by specifying a tag order vector in the registry located at:
181 ///
182 /// `HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ GroupOrderList`
183 ///
184 /// Tags are only evaluated for Kernel Driver and File System Driver start type services that
185 /// have Boot or System start modes.
186 pub TagId: Option<u32>,
187 /// Estimated time required, in milliseconds, for a pending start, stop, pause, or continue
188 /// operation. After the specified time has elapsed, the service makes its next call to the
189 /// SetServiceStatus method with either an incremented CheckPoint value or a change in
190 /// CurrentState. If the amount of time specified by WaitHint passes, and CheckPoint has not
191 /// been incremented, or CurrentState has not changed, the service control manager or service
192 /// control program assumes that an error has occurred.
193 pub WaitHint: Option<u32>,
194}