Crates.io | windows_service_controller |
lib.rs | windows_service_controller |
version | 0.1.4 |
source | src |
created_at | 2024-03-27 07:25:41.851249 |
updated_at | 2024-10-29 13:00:59.683021 |
description | A library to control windows service |
homepage | https://github.com/1412150209/rc_windows_service_controller |
repository | https://github.com/1412150209/rc_windows_service_controller |
max_upload_size | |
id | 1187581 |
size | 36,631 |
Make it easier to control windows service.
Current features:
Basic operations:
Open an existing service
Create a new service
Delete a service
Query the status of service
Edit config of service
# Cargo.toml
[dependencies]
windows_service_controller = "0.1"
use windows_service_controller::WindowsService;
use windows_service_controller::dword::service_access;
fn open_service() {
let service = WindowsService::open("WSearch",
Some(service_access::GENERIC_READ), None);
match service {
Ok(s) => {
println!("{:?}", s.config)
}
Err(e) => {
println!("{}", e)
}
}
}
use windows_service_controller::WindowsService;
use windows_service_controller::dword::{sc_manager_access,
service_access, service_type, service_start_type, service_error_control};
fn create_service() {
let service = WindowsService::new(
"Lers",
None,
Some(sc_manager_access::GENERIC_WRITE),
Some(service_access::GENERIC_WRITE),
service_type::SERVICE_WIN32_OWN_PROCESS,
service_start_type::SERVICE_DEMAND_START,
service_error_control::SERVICE_ERROR_NORMAL,
"Path to Binary",
None,
);
match service {
Ok(s) => {
println!("{:?}", s.config)
}
Err(e) => {
println!("{}", e)
}
}
}
use windows_service_controller::WindowsService;
fn delete_service() {
let service = WindowsService::open("Lers", None, None);
match service {
Ok(s) => match s.delete_service() {
Ok(_) => {
println!("succeed")
}
Err(e) => {
println!("{}", e);
}
},
Err(e) => {
println!("{}", e);
}
}
}
use windows_service_controller::{WindowsService, PWSTR};
fn update_service_config() {
let service = WindowsService::open("Lers", None, None);
match service {
Ok(mut s) => {
s.config.lpDisplayName = PWSTR!("lers test");
match s.update_service_config(None) {
Ok(_) => {
println!("succeed")
}
Err(e) => {
println!("{}", e);
}
}
}
Err(e) => {
println!("{}", e);
}
}
}
BUG: "lpServiceStartName" can't be edit.
fn start_service() {
let service = WindowsService::open("InstallService", None, None);
match service {
Ok(s) => {
match s.start_service() {
Ok(_) => {
println!("succeed")
}
Err(e) => {
println!("{}", e);
}
}
}
Err(e) => {
println!("{}", e);
}
}
}
fn stop_service() {
let service = WindowsService::open("InstallService", None, None);
match service {
Ok(s) => {
match s.stop_service() {
Ok(_) => {
println!("succeed")
}
Err(e) => {
println!("{}", e);
}
}
}
Err(e) => {
println!("{}", e);
}
}
}