pub struct ServiceManager { /* private fields */ }Expand description
Service manager.
Implementations§
Source§impl ServiceManager
impl ServiceManager
Sourcepub fn local_computer(
database: Option<impl AsRef<OsStr>>,
request_access: ServiceManagerAccess,
) -> Result<Self>
pub fn local_computer( database: Option<impl AsRef<OsStr>>, request_access: ServiceManagerAccess, ) -> Result<Self>
Connect to local services database.
§Arguments
database- The name of database to connect to. PassNoneto connect to active database.request_access- Desired access permissions.
Examples found in repository?
examples/service_config.rs (line 12)
2fn main() -> windows_service::Result<()> {
3 use std::env;
4 use windows_service::{
5 service::ServiceAccess,
6 service_manager::{ServiceManager, ServiceManagerAccess},
7 };
8
9 let service_name = env::args().nth(1).unwrap_or("netlogon".to_owned());
10
11 let manager_access = ServiceManagerAccess::CONNECT;
12 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
13
14 let service = service_manager.open_service(service_name, ServiceAccess::QUERY_CONFIG)?;
15
16 let config = service.query_config()?;
17 println!("{:#?}", config);
18 Ok(())
19}More examples
examples/pause_continue.rs (line 22)
12fn main() -> windows_service::Result<()> {
13 use std::env;
14 use windows_service::{
15 service::ServiceAccess,
16 service_manager::{ServiceManager, ServiceManagerAccess},
17 };
18
19 let service_name = env::args().nth(1).unwrap_or("Winmgmt".to_owned());
20
21 let manager_access = ServiceManagerAccess::CONNECT;
22 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
23
24 let service = service_manager.open_service(&service_name, ServiceAccess::PAUSE_CONTINUE)?;
25
26 println!("Pause {}", service_name);
27 let paused_state = service.pause()?;
28 println!("{:?}", paused_state.current_state);
29
30 println!("Resume {}", service_name);
31 let resumed_state = service.resume()?;
32 println!("{:?}", resumed_state.current_state);
33
34 Ok(())
35}examples/notify_service.rs (line 21)
11fn main() -> windows_service::Result<()> {
12 use std::env;
13 use windows_service::{
14 service::{ServiceAccess, UserEventCode},
15 service_manager::{ServiceManager, ServiceManagerAccess},
16 };
17
18 let service_name = env::args().nth(1).unwrap_or("ping_service".to_owned());
19
20 let manager_access = ServiceManagerAccess::CONNECT;
21 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
22
23 let service = service_manager.open_service(
24 &service_name,
25 ServiceAccess::PAUSE_CONTINUE | ServiceAccess::USER_DEFINED_CONTROL,
26 )?;
27
28 const NO_OP: UserEventCode = unsafe { UserEventCode::from_unchecked(128) };
29 const CUSTOM_STOP: UserEventCode = unsafe { UserEventCode::from_unchecked(130) };
30
31 println!("Send `NO_OP` notification to {}", service_name);
32 let state = service.notify(NO_OP)?;
33 println!("{:?}", state.current_state);
34
35 println!("Send `CUSTOM_STOP` notification to {}", service_name);
36 let state = service.notify(CUSTOM_STOP)?;
37 println!("{:?}", state.current_state);
38
39 Ok(())
40}examples/install_service.rs (line 10)
2fn main() -> windows_service::Result<()> {
3 use std::ffi::OsString;
4 use windows_service::{
5 service::{ServiceAccess, ServiceErrorControl, ServiceInfo, ServiceStartType, ServiceType},
6 service_manager::{ServiceManager, ServiceManagerAccess},
7 };
8
9 let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
10 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
11
12 // This example installs the service defined in `examples/ping_service.rs`.
13 // In the real world code you would set the executable path to point to your own binary
14 // that implements windows service.
15 let service_binary_path = ::std::env::current_exe()
16 .unwrap()
17 .with_file_name("ping_service.exe");
18
19 let service_info = ServiceInfo {
20 name: OsString::from("ping_service"),
21 display_name: OsString::from("Ping service"),
22 service_type: ServiceType::OWN_PROCESS,
23 start_type: ServiceStartType::OnDemand,
24 error_control: ServiceErrorControl::Normal,
25 executable_path: service_binary_path,
26 launch_arguments: vec![],
27 dependencies: vec![],
28 account_name: None, // run as System
29 account_password: None,
30 };
31 let service = service_manager.create_service(&service_info, ServiceAccess::CHANGE_CONFIG)?;
32 service.set_description("Windows service example from windows-service-rs")?;
33 Ok(())
34}examples/uninstall_service.rs (line 15)
2fn main() -> windows_service::Result<()> {
3 use std::{
4 thread::sleep,
5 time::{Duration, Instant},
6 };
7
8 use windows_service::{
9 service::{ServiceAccess, ServiceState},
10 service_manager::{ServiceManager, ServiceManagerAccess},
11 };
12 use windows_sys::Win32::Foundation::ERROR_SERVICE_DOES_NOT_EXIST;
13
14 let manager_access = ServiceManagerAccess::CONNECT;
15 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
16
17 let service_access = ServiceAccess::QUERY_STATUS | ServiceAccess::STOP | ServiceAccess::DELETE;
18 let service = service_manager.open_service("ping_service", service_access)?;
19
20 // The service will be marked for deletion as long as this function call succeeds.
21 // However, it will not be deleted from the database until it is stopped and all open handles to it are closed.
22 service.delete()?;
23 // Our handle to it is not closed yet. So we can still query it.
24 if service.query_status()?.current_state != ServiceState::Stopped {
25 // If the service cannot be stopped, it will be deleted when the system restarts.
26 service.stop()?;
27 }
28 // Explicitly close our open handle to the service. This is automatically called when `service` goes out of scope.
29 drop(service);
30
31 // Win32 API does not give us a way to wait for service deletion.
32 // To check if the service is deleted from the database, we have to poll it ourselves.
33 let start = Instant::now();
34 let timeout = Duration::from_secs(5);
35 while start.elapsed() < timeout {
36 if let Err(windows_service::Error::Winapi(e)) =
37 service_manager.open_service("ping_service", ServiceAccess::QUERY_STATUS)
38 {
39 if e.raw_os_error() == Some(ERROR_SERVICE_DOES_NOT_EXIST as i32) {
40 println!("ping_service is deleted.");
41 return Ok(());
42 }
43 }
44 sleep(Duration::from_secs(1));
45 }
46 println!("ping_service is marked for deletion.");
47
48 Ok(())
49}examples/service_failure_actions.rs (line 17)
2fn main() -> windows_service::Result<()> {
3 use std::ffi::OsString;
4 use std::time::Duration;
5 use windows_service::{
6 service::{
7 ServiceAccess, ServiceAction, ServiceActionType, ServiceErrorControl,
8 ServiceFailureActions, ServiceFailureResetPeriod, ServiceInfo, ServiceStartType,
9 ServiceType,
10 },
11 service_manager::{ServiceManager, ServiceManagerAccess},
12 };
13
14 const SERVICE_NAME: &str = "service_failure_actions_example";
15
16 let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
17 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
18
19 let service_binary_path = ::std::env::current_exe()
20 .unwrap()
21 .with_file_name("service_failure_actions.exe");
22
23 let service_info = ServiceInfo {
24 name: OsString::from(SERVICE_NAME),
25 display_name: OsString::from("Service Failure Actions Example"),
26 service_type: ServiceType::OWN_PROCESS,
27 start_type: ServiceStartType::OnDemand,
28 error_control: ServiceErrorControl::Normal,
29 executable_path: service_binary_path,
30 launch_arguments: vec![],
31 dependencies: vec![],
32 account_name: None, // run as System
33 account_password: None,
34 };
35
36 let service_access = ServiceAccess::QUERY_CONFIG
37 | ServiceAccess::CHANGE_CONFIG
38 | ServiceAccess::START
39 | ServiceAccess::DELETE;
40
41 println!("Create or open the service {}", SERVICE_NAME);
42 let service = service_manager
43 .create_service(&service_info, service_access)
44 .or(service_manager.open_service(SERVICE_NAME, service_access))?;
45
46 let actions = vec![
47 ServiceAction {
48 action_type: ServiceActionType::Restart,
49 delay: Duration::from_secs(5),
50 },
51 ServiceAction {
52 action_type: ServiceActionType::RunCommand,
53 delay: Duration::from_secs(10),
54 },
55 ServiceAction {
56 action_type: ServiceActionType::None,
57 delay: Duration::default(),
58 },
59 ];
60
61 println!("Update failure actions");
62 let failure_actions = ServiceFailureActions {
63 reset_period: ServiceFailureResetPeriod::After(Duration::from_secs(86400 * 2)),
64 reboot_msg: None,
65 command: Some(OsString::from("ping 127.0.0.1")),
66 actions: Some(actions),
67 };
68 service.update_failure_actions(failure_actions)?;
69
70 println!("Query failure actions");
71 let updated_failure_actions = service.get_failure_actions()?;
72 println!("{:#?}", updated_failure_actions);
73
74 println!("Enable failure actions on non-crash failures");
75 service.set_failure_actions_on_non_crash_failures(true)?;
76
77 println!("Query failure actions on non-crash failures enabled");
78 let failure_actions_flag = service.get_failure_actions_on_non_crash_failures()?;
79 println!(
80 "Failure actions on non-crash failures enabled: {}",
81 failure_actions_flag
82 );
83
84 println!("Delete the service {}", SERVICE_NAME);
85 service.delete()?;
86
87 Ok(())
88}Sourcepub fn remote_computer(
machine: impl AsRef<OsStr>,
database: Option<impl AsRef<OsStr>>,
request_access: ServiceManagerAccess,
) -> Result<Self>
pub fn remote_computer( machine: impl AsRef<OsStr>, database: Option<impl AsRef<OsStr>>, request_access: ServiceManagerAccess, ) -> Result<Self>
Connect to remote services database.
§Arguments
machine- The name of remote machine.database- The name of database to connect to. PassNoneto connect to active database.request_access- desired access permissions.
Sourcepub fn create_service(
&self,
service_info: &ServiceInfo,
service_access: ServiceAccess,
) -> Result<Service>
pub fn create_service( &self, service_info: &ServiceInfo, service_access: ServiceAccess, ) -> Result<Service>
Create a service.
§Arguments
service_info- The service information that will be saved to the system services registry.service_access- Desired access permissions for the returnedServiceinstance.
§Example
use std::ffi::OsString;
use std::path::PathBuf;
use windows_service::service::{
ServiceAccess, ServiceErrorControl, ServiceInfo, ServiceStartType, ServiceType,
};
use windows_service::service_manager::{ServiceManager, ServiceManagerAccess};
fn main() -> windows_service::Result<()> {
let manager =
ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CREATE_SERVICE)?;
let my_service_info = ServiceInfo {
name: OsString::from("my_service"),
display_name: OsString::from("My service"),
service_type: ServiceType::OWN_PROCESS,
start_type: ServiceStartType::OnDemand,
error_control: ServiceErrorControl::Normal,
executable_path: PathBuf::from(r"C:\path\to\my\service.exe"),
launch_arguments: vec![],
dependencies: vec![],
account_name: None, // run as System
account_password: None,
};
let my_service = manager.create_service(&my_service_info, ServiceAccess::QUERY_STATUS)?;
Ok(())
}Examples found in repository?
examples/install_service.rs (line 31)
2fn main() -> windows_service::Result<()> {
3 use std::ffi::OsString;
4 use windows_service::{
5 service::{ServiceAccess, ServiceErrorControl, ServiceInfo, ServiceStartType, ServiceType},
6 service_manager::{ServiceManager, ServiceManagerAccess},
7 };
8
9 let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
10 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
11
12 // This example installs the service defined in `examples/ping_service.rs`.
13 // In the real world code you would set the executable path to point to your own binary
14 // that implements windows service.
15 let service_binary_path = ::std::env::current_exe()
16 .unwrap()
17 .with_file_name("ping_service.exe");
18
19 let service_info = ServiceInfo {
20 name: OsString::from("ping_service"),
21 display_name: OsString::from("Ping service"),
22 service_type: ServiceType::OWN_PROCESS,
23 start_type: ServiceStartType::OnDemand,
24 error_control: ServiceErrorControl::Normal,
25 executable_path: service_binary_path,
26 launch_arguments: vec![],
27 dependencies: vec![],
28 account_name: None, // run as System
29 account_password: None,
30 };
31 let service = service_manager.create_service(&service_info, ServiceAccess::CHANGE_CONFIG)?;
32 service.set_description("Windows service example from windows-service-rs")?;
33 Ok(())
34}More examples
examples/service_failure_actions.rs (line 43)
2fn main() -> windows_service::Result<()> {
3 use std::ffi::OsString;
4 use std::time::Duration;
5 use windows_service::{
6 service::{
7 ServiceAccess, ServiceAction, ServiceActionType, ServiceErrorControl,
8 ServiceFailureActions, ServiceFailureResetPeriod, ServiceInfo, ServiceStartType,
9 ServiceType,
10 },
11 service_manager::{ServiceManager, ServiceManagerAccess},
12 };
13
14 const SERVICE_NAME: &str = "service_failure_actions_example";
15
16 let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
17 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
18
19 let service_binary_path = ::std::env::current_exe()
20 .unwrap()
21 .with_file_name("service_failure_actions.exe");
22
23 let service_info = ServiceInfo {
24 name: OsString::from(SERVICE_NAME),
25 display_name: OsString::from("Service Failure Actions Example"),
26 service_type: ServiceType::OWN_PROCESS,
27 start_type: ServiceStartType::OnDemand,
28 error_control: ServiceErrorControl::Normal,
29 executable_path: service_binary_path,
30 launch_arguments: vec![],
31 dependencies: vec![],
32 account_name: None, // run as System
33 account_password: None,
34 };
35
36 let service_access = ServiceAccess::QUERY_CONFIG
37 | ServiceAccess::CHANGE_CONFIG
38 | ServiceAccess::START
39 | ServiceAccess::DELETE;
40
41 println!("Create or open the service {}", SERVICE_NAME);
42 let service = service_manager
43 .create_service(&service_info, service_access)
44 .or(service_manager.open_service(SERVICE_NAME, service_access))?;
45
46 let actions = vec![
47 ServiceAction {
48 action_type: ServiceActionType::Restart,
49 delay: Duration::from_secs(5),
50 },
51 ServiceAction {
52 action_type: ServiceActionType::RunCommand,
53 delay: Duration::from_secs(10),
54 },
55 ServiceAction {
56 action_type: ServiceActionType::None,
57 delay: Duration::default(),
58 },
59 ];
60
61 println!("Update failure actions");
62 let failure_actions = ServiceFailureActions {
63 reset_period: ServiceFailureResetPeriod::After(Duration::from_secs(86400 * 2)),
64 reboot_msg: None,
65 command: Some(OsString::from("ping 127.0.0.1")),
66 actions: Some(actions),
67 };
68 service.update_failure_actions(failure_actions)?;
69
70 println!("Query failure actions");
71 let updated_failure_actions = service.get_failure_actions()?;
72 println!("{:#?}", updated_failure_actions);
73
74 println!("Enable failure actions on non-crash failures");
75 service.set_failure_actions_on_non_crash_failures(true)?;
76
77 println!("Query failure actions on non-crash failures enabled");
78 let failure_actions_flag = service.get_failure_actions_on_non_crash_failures()?;
79 println!(
80 "Failure actions on non-crash failures enabled: {}",
81 failure_actions_flag
82 );
83
84 println!("Delete the service {}", SERVICE_NAME);
85 service.delete()?;
86
87 Ok(())
88}Sourcepub fn open_service(
&self,
name: impl AsRef<OsStr>,
request_access: ServiceAccess,
) -> Result<Service>
pub fn open_service( &self, name: impl AsRef<OsStr>, request_access: ServiceAccess, ) -> Result<Service>
Open an existing service.
§Arguments
name- The service name.request_access- Desired permissions for the returnedServiceinstance.
§Example
use windows_service::service::ServiceAccess;
use windows_service::service_manager::{ServiceManager, ServiceManagerAccess};
let manager = ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CONNECT)?;
let my_service = manager.open_service("my_service", ServiceAccess::QUERY_STATUS)?;Examples found in repository?
examples/service_config.rs (line 14)
2fn main() -> windows_service::Result<()> {
3 use std::env;
4 use windows_service::{
5 service::ServiceAccess,
6 service_manager::{ServiceManager, ServiceManagerAccess},
7 };
8
9 let service_name = env::args().nth(1).unwrap_or("netlogon".to_owned());
10
11 let manager_access = ServiceManagerAccess::CONNECT;
12 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
13
14 let service = service_manager.open_service(service_name, ServiceAccess::QUERY_CONFIG)?;
15
16 let config = service.query_config()?;
17 println!("{:#?}", config);
18 Ok(())
19}More examples
examples/pause_continue.rs (line 24)
12fn main() -> windows_service::Result<()> {
13 use std::env;
14 use windows_service::{
15 service::ServiceAccess,
16 service_manager::{ServiceManager, ServiceManagerAccess},
17 };
18
19 let service_name = env::args().nth(1).unwrap_or("Winmgmt".to_owned());
20
21 let manager_access = ServiceManagerAccess::CONNECT;
22 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
23
24 let service = service_manager.open_service(&service_name, ServiceAccess::PAUSE_CONTINUE)?;
25
26 println!("Pause {}", service_name);
27 let paused_state = service.pause()?;
28 println!("{:?}", paused_state.current_state);
29
30 println!("Resume {}", service_name);
31 let resumed_state = service.resume()?;
32 println!("{:?}", resumed_state.current_state);
33
34 Ok(())
35}examples/notify_service.rs (lines 23-26)
11fn main() -> windows_service::Result<()> {
12 use std::env;
13 use windows_service::{
14 service::{ServiceAccess, UserEventCode},
15 service_manager::{ServiceManager, ServiceManagerAccess},
16 };
17
18 let service_name = env::args().nth(1).unwrap_or("ping_service".to_owned());
19
20 let manager_access = ServiceManagerAccess::CONNECT;
21 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
22
23 let service = service_manager.open_service(
24 &service_name,
25 ServiceAccess::PAUSE_CONTINUE | ServiceAccess::USER_DEFINED_CONTROL,
26 )?;
27
28 const NO_OP: UserEventCode = unsafe { UserEventCode::from_unchecked(128) };
29 const CUSTOM_STOP: UserEventCode = unsafe { UserEventCode::from_unchecked(130) };
30
31 println!("Send `NO_OP` notification to {}", service_name);
32 let state = service.notify(NO_OP)?;
33 println!("{:?}", state.current_state);
34
35 println!("Send `CUSTOM_STOP` notification to {}", service_name);
36 let state = service.notify(CUSTOM_STOP)?;
37 println!("{:?}", state.current_state);
38
39 Ok(())
40}examples/uninstall_service.rs (line 18)
2fn main() -> windows_service::Result<()> {
3 use std::{
4 thread::sleep,
5 time::{Duration, Instant},
6 };
7
8 use windows_service::{
9 service::{ServiceAccess, ServiceState},
10 service_manager::{ServiceManager, ServiceManagerAccess},
11 };
12 use windows_sys::Win32::Foundation::ERROR_SERVICE_DOES_NOT_EXIST;
13
14 let manager_access = ServiceManagerAccess::CONNECT;
15 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
16
17 let service_access = ServiceAccess::QUERY_STATUS | ServiceAccess::STOP | ServiceAccess::DELETE;
18 let service = service_manager.open_service("ping_service", service_access)?;
19
20 // The service will be marked for deletion as long as this function call succeeds.
21 // However, it will not be deleted from the database until it is stopped and all open handles to it are closed.
22 service.delete()?;
23 // Our handle to it is not closed yet. So we can still query it.
24 if service.query_status()?.current_state != ServiceState::Stopped {
25 // If the service cannot be stopped, it will be deleted when the system restarts.
26 service.stop()?;
27 }
28 // Explicitly close our open handle to the service. This is automatically called when `service` goes out of scope.
29 drop(service);
30
31 // Win32 API does not give us a way to wait for service deletion.
32 // To check if the service is deleted from the database, we have to poll it ourselves.
33 let start = Instant::now();
34 let timeout = Duration::from_secs(5);
35 while start.elapsed() < timeout {
36 if let Err(windows_service::Error::Winapi(e)) =
37 service_manager.open_service("ping_service", ServiceAccess::QUERY_STATUS)
38 {
39 if e.raw_os_error() == Some(ERROR_SERVICE_DOES_NOT_EXIST as i32) {
40 println!("ping_service is deleted.");
41 return Ok(());
42 }
43 }
44 sleep(Duration::from_secs(1));
45 }
46 println!("ping_service is marked for deletion.");
47
48 Ok(())
49}examples/service_failure_actions.rs (line 44)
2fn main() -> windows_service::Result<()> {
3 use std::ffi::OsString;
4 use std::time::Duration;
5 use windows_service::{
6 service::{
7 ServiceAccess, ServiceAction, ServiceActionType, ServiceErrorControl,
8 ServiceFailureActions, ServiceFailureResetPeriod, ServiceInfo, ServiceStartType,
9 ServiceType,
10 },
11 service_manager::{ServiceManager, ServiceManagerAccess},
12 };
13
14 const SERVICE_NAME: &str = "service_failure_actions_example";
15
16 let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
17 let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;
18
19 let service_binary_path = ::std::env::current_exe()
20 .unwrap()
21 .with_file_name("service_failure_actions.exe");
22
23 let service_info = ServiceInfo {
24 name: OsString::from(SERVICE_NAME),
25 display_name: OsString::from("Service Failure Actions Example"),
26 service_type: ServiceType::OWN_PROCESS,
27 start_type: ServiceStartType::OnDemand,
28 error_control: ServiceErrorControl::Normal,
29 executable_path: service_binary_path,
30 launch_arguments: vec![],
31 dependencies: vec![],
32 account_name: None, // run as System
33 account_password: None,
34 };
35
36 let service_access = ServiceAccess::QUERY_CONFIG
37 | ServiceAccess::CHANGE_CONFIG
38 | ServiceAccess::START
39 | ServiceAccess::DELETE;
40
41 println!("Create or open the service {}", SERVICE_NAME);
42 let service = service_manager
43 .create_service(&service_info, service_access)
44 .or(service_manager.open_service(SERVICE_NAME, service_access))?;
45
46 let actions = vec![
47 ServiceAction {
48 action_type: ServiceActionType::Restart,
49 delay: Duration::from_secs(5),
50 },
51 ServiceAction {
52 action_type: ServiceActionType::RunCommand,
53 delay: Duration::from_secs(10),
54 },
55 ServiceAction {
56 action_type: ServiceActionType::None,
57 delay: Duration::default(),
58 },
59 ];
60
61 println!("Update failure actions");
62 let failure_actions = ServiceFailureActions {
63 reset_period: ServiceFailureResetPeriod::After(Duration::from_secs(86400 * 2)),
64 reboot_msg: None,
65 command: Some(OsString::from("ping 127.0.0.1")),
66 actions: Some(actions),
67 };
68 service.update_failure_actions(failure_actions)?;
69
70 println!("Query failure actions");
71 let updated_failure_actions = service.get_failure_actions()?;
72 println!("{:#?}", updated_failure_actions);
73
74 println!("Enable failure actions on non-crash failures");
75 service.set_failure_actions_on_non_crash_failures(true)?;
76
77 println!("Query failure actions on non-crash failures enabled");
78 let failure_actions_flag = service.get_failure_actions_on_non_crash_failures()?;
79 println!(
80 "Failure actions on non-crash failures enabled: {}",
81 failure_actions_flag
82 );
83
84 println!("Delete the service {}", SERVICE_NAME);
85 service.delete()?;
86
87 Ok(())
88}Sourcepub fn service_name_from_display_name(
&self,
display_name: impl AsRef<OsStr>,
) -> Result<OsString>
pub fn service_name_from_display_name( &self, display_name: impl AsRef<OsStr>, ) -> Result<OsString>
Return the service name given a service display name.
§Arguments
name- A service display name.
§Example
use windows_service::service_manager::{ServiceManager, ServiceManagerAccess};
let manager = ServiceManager::local_computer(None::<&str>, ServiceManagerAccess::CONNECT)?;
let my_service_name = manager.service_name_from_display_name("My Service Display Name")?;Auto Trait Implementations§
impl Freeze for ServiceManager
impl RefUnwindSafe for ServiceManager
impl !Send for ServiceManager
impl !Sync for ServiceManager
impl Unpin for ServiceManager
impl UnwindSafe for ServiceManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more