pub struct WindowsService {
    pub config: QUERY_SERVICE_CONFIGW,
    /* private fields */
}
Expand description

windows服务类

Fields§

§config: QUERY_SERVICE_CONFIGW

Implementations§

source§

impl WindowsService

source

pub fn open( name: &str, service_access: Option<ServiceAccess>, sc_manager_access: Option<ScManagerAccess> ) -> Result<WindowsService, ServiceError>

§通过服务名打开一个服务实例
§参数
§input:
  • name: 服务名称(不是显示名称)
  • service_access: 默认为SERVICE_ALL_ACCESS
  • sc_manager_access: 默认为SC_MANAGER_CONNECT
§output:
  • Result<WindowsService,ServiceError>
§例子
use windows_service_controller::dword::service_access;
use windows_service_controller::WindowsService;
let service = WindowsService::open("Lers", Some(service_access::GENERIC_READ),None);
source

pub fn query_service_status(&self) -> Result<ServiceStatus, ServiceError>

§请求当前服务状态
source

pub fn new( name: &str, display_name: Option<&str>, sc_manager_access: Option<ScManagerAccess>, service_access: Option<ServiceAccess>, service_type: ServiceType, service_start_type: ServiceStartType, error_control: ServiceErrorControl, binary_path: &str, dependencies: Option<Vec<&str>> ) -> Result<WindowsService, ServiceError>

§新建一个服务
§参数
§input:
  • name: 服务名称(最长256字符,斜杠无效)
  • display_name: 服务显示名称,不写与name一致
  • sc_manager_access: SCM的访问权限,默认SC_MANAGER_ALL_ACCESS,常量在 sc_service_access::
  • service_access: 对服务的访问权限,默认SERVICE_ALL_ACCESS,常量在 service_access::
  • service_type: 服务类型,常量在 service_type::
  • service_start_type: 服务启动选项,常量在 service_start_type::
  • error_control: 错误控制,常量在 service_error_control::
  • binary_path: 需要启动的文件路径,路径可以包含启动的参数
  • dependencies: 服务的依赖项
§output:
  • Result<WindowsService,ServiceError>
§例子
use windows_service_controller::dword::{service_error_control, service_start_type, service_type};
use windows_service_controller::WindowsService;
let service = WindowsService::new(
    "Lers",
    None,
    None,
    None,
    service_type::SERVICE_WIN32_OWN_PROCESS,
    service_start_type::SERVICE_DEMAND_START,
    service_error_control::SERVICE_ERROR_NORMAL,
    "D:\\ENGLISH\\Rust\\hot_update\\target\\debug\\hot_update.exe",
    None,
 );
source

pub fn delete_service(&self) -> Result<(), ServiceError>

§删除该服务
§参数
§output:
  • Result<(),ServiceError>
source

pub fn update_service_config( &self, passwd: Option<&str> ) -> Result<(), ServiceError>

§更新服务配置
§参数
§input:
  • passwd: 修改服务密码,不修改请传入None
§output:
  • Result<(),ServiceError>
§例子
use windows_service_controller::{PWSTR, WindowsService};
let mut service = WindowsService::open("Lers", None, None).unwrap();

service.config.lpDisplayName = PWSTR!("lers233");
service.update_service_config(None).unwrap()
§BUG

似乎无法修改lpServiceStartName字段

Trait Implementations§

source§

impl Drop for WindowsService

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>,

§

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>,

§

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.