pub struct ServiceManager { /* private fields */ }
Expand description
Manages Windows services, providing functionalities to create, retrieve, and control services.
Implementations§
Source§impl ServiceManager
§Examples
let service_manager = ServiceManager::new()?;
let service_name = "test";
let service_path = r"C:\Windows\system32\test.sys";
let service_handle = service_manager.create_or_get(ServiceConfig {
service_name: service_name.to_string(),
display_name: service_name.to_string(),
binary_path: "invalid path test".to_string(),
start_type: ServiceStartType::DemandStart,
service_type: ServiceType::KernelDriver,
..Default::default()
})?;
assert_eq!(
service_handle.get_start_type()?,
ServiceStartType::DemandStart
);
service_handle.update_config(ServiceConfig {
display_name: service_name.to_string(),
binary_path: service_path.to_string(),
service_type: ServiceType::KernelDriver,
..Default::default()
})?;
service_handle.start_blocking()?;
assert_eq!(service_handle.state()?, ServiceState::Running);
service_handle.stop_blocking()?;
assert_eq!(service_handle.state()?, ServiceState::Stopped);
std::thread::sleep(std::time::Duration::from_secs(2));
service_handle.delete()?;
impl ServiceManager
§Examples
let service_manager = ServiceManager::new()?;
let service_name = "test";
let service_path = r"C:\Windows\system32\test.sys";
let service_handle = service_manager.create_or_get(ServiceConfig {
service_name: service_name.to_string(),
display_name: service_name.to_string(),
binary_path: "invalid path test".to_string(),
start_type: ServiceStartType::DemandStart,
service_type: ServiceType::KernelDriver,
..Default::default()
})?;
assert_eq!(
service_handle.get_start_type()?,
ServiceStartType::DemandStart
);
service_handle.update_config(ServiceConfig {
display_name: service_name.to_string(),
binary_path: service_path.to_string(),
service_type: ServiceType::KernelDriver,
..Default::default()
})?;
service_handle.start_blocking()?;
assert_eq!(service_handle.state()?, ServiceState::Running);
service_handle.stop_blocking()?;
assert_eq!(service_handle.state()?, ServiceState::Stopped);
std::thread::sleep(std::time::Duration::from_secs(2));
service_handle.delete()?;
Sourcepub fn new() -> Result<Self, ServiceManagerError>
pub fn new() -> Result<Self, ServiceManagerError>
Creates a new ServiceManager
with access to the service control manager.
§Errors
This function will return an error if it can’t open the service control manager.
Sourcepub fn create_service(
&self,
options: ServiceConfig,
) -> Result<ServiceHandle, CreateServiceError>
pub fn create_service( &self, options: ServiceConfig, ) -> Result<ServiceHandle, CreateServiceError>
Creates a new service with the specified configuration.
§Errors
This function will return an error if it can’t create the service.
Sourcepub fn get_service(
&self,
service_name: String,
) -> Result<ServiceHandle, OpenServiceError>
pub fn get_service( &self, service_name: String, ) -> Result<ServiceHandle, OpenServiceError>
Retrieves an existing service by name.
§Errors
This function will return an error if it can’t retrieve the service.
Sourcepub fn create_or_get(
&self,
options: ServiceConfig,
) -> Result<ServiceHandle, CreateServiceError>
pub fn create_or_get( &self, options: ServiceConfig, ) -> Result<ServiceHandle, CreateServiceError>
Creates a new service if it doesn’t exist, otherwise retrieves the existing service.
§Errors
This function will return an error if it can’t create or retrieve the service.
Trait Implementations§
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