pub struct WindowsService {
pub config: QUERY_SERVICE_CONFIGW,
/* private fields */
}
Expand description
windows服务类
Fields§
§config: QUERY_SERVICE_CONFIGW
Implementations§
source§impl WindowsService
impl WindowsService
sourcepub fn open(
name: &str,
service_access: Option<ServiceAccess>,
sc_manager_access: Option<ScManagerAccess>
) -> Result<WindowsService, ServiceError>
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);
sourcepub fn query_service_status(&self) -> Result<ServiceStatus, ServiceError>
pub fn query_service_status(&self) -> Result<ServiceStatus, ServiceError>
§请求当前服务状态
sourcepub 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>
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,
);
sourcepub fn delete_service(&self) -> Result<(), ServiceError>
pub fn delete_service(&self) -> Result<(), ServiceError>
sourcepub fn update_service_config(
&self,
passwd: Option<&str>
) -> Result<(), ServiceError>
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§
Auto Trait Implementations§
impl Freeze for WindowsService
impl RefUnwindSafe for WindowsService
impl !Send for WindowsService
impl !Sync for WindowsService
impl Unpin for WindowsService
impl UnwindSafe for WindowsService
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