mullvad / windows-service-rs

Windows services in Rust
Apache License 2.0
525 stars 85 forks source link

problem for starting service #131

Open SaeedSafi1999 opened 4 months ago

SaeedSafi1999 commented 4 months ago

I complete my code following your ping service code example but when I want to start service return windows error:1053 The service is not responding to the control function. how to fix that?

faern commented 1 month ago

If this is still a problem, can you provide more information? For example code where this happens? It sounds like your code fails to return in a timely manner and report back to Windows that it started successfully?

Does the ping example work for you, but not your program? Then can you try massaging them until you figure out where the difference is?

Jackolix commented 1 week ago

i have a similar Problem when starting my windows service I created. The service is created but cannot be started from the rust program itself. What did i wrong?

ERROR: IO error in winapi call

#[cfg(windows)]
async fn setup_service() -> windows_service::Result<()> {
    use std::ffi::OsString;
    use windows_service::{
        service::{ServiceAccess, ServiceErrorControl, ServiceInfo, ServiceStartType, ServiceType},
        service_manager::{ServiceManager, ServiceManagerAccess},
    };

    let manager_access = ServiceManagerAccess::CONNECT | ServiceManagerAccess::CREATE_SERVICE;
    let service_manager = ServiceManager::local_computer(None::<&str>, manager_access)?;

    let service_binary_path = Path::new(INSTALL_DIR).join(EXE_NAME);

    let service_info = ServiceInfo {
        name: OsString::from("Installer"),
        display_name: OsString::from("Installer Service"),
        service_type: ServiceType::OWN_PROCESS,
        start_type: ServiceStartType::AutoStart,
        error_control: ServiceErrorControl::Normal,
        executable_path: service_binary_path,
        launch_arguments: vec![],
        dependencies: vec![],
        account_name: None,
        account_password: None,
    };

    let service = service_manager.create_service(&service_info, ServiceAccess::CHANGE_CONFIG)?;
    service.set_description("Interface")?;
    service.start(&[OsStr::new("Init start from Installer")])?; // Error happens here
    Ok(())
}