Struct ServiceManager

Source
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()?;
Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Drop for ServiceManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.