windows_erg/service/
mod.rs1#![allow(clippy::module_inception)]
7
8mod manager;
9mod service;
10mod status;
11mod types;
12
13pub use manager::ServiceManager;
14pub use service::Service;
15pub use status::ServiceStatus;
16pub use types::{ServiceAccess, ServiceControl, ServiceManagerAccess, ServiceState};
17
18use std::time::Duration;
19
20use crate::Result;
21
22pub fn query(name: &str) -> Result<ServiceStatus> {
24 Service::open(name)?.query()
25}
26
27pub fn start(name: &str) -> Result<()> {
29 Service::open_with_access(name, ServiceAccess::Start)?.start()
30}
31
32pub fn stop(name: &str) -> Result<()> {
34 Service::open_with_access(name, ServiceAccess::Stop)?.stop()
35}
36
37pub fn restart(name: &str, timeout: Duration) -> Result<()> {
39 Service::open_with_access(
40 name,
41 ServiceAccess::Custom(
42 ServiceAccess::QueryStatus.to_windows()
43 | ServiceAccess::Start.to_windows()
44 | ServiceAccess::Stop.to_windows(),
45 ),
46 )?
47 .restart(timeout)
48}
49
50pub fn list() -> Result<Vec<ServiceStatus>> {
52 ServiceManager::connect()?.list()
53}
54
55pub fn list_with_buffer(out_services: &mut Vec<ServiceStatus>) -> Result<usize> {
59 ServiceManager::connect()?.list_with_buffer(out_services)
60}
61
62pub fn list_with_filter<F>(out_services: &mut Vec<ServiceStatus>, filter: F) -> Result<usize>
66where
67 F: Fn(&ServiceStatus) -> bool,
68{
69 ServiceManager::connect()?.list_with_filter(out_services, filter)
70}