#windows #run-time

windows-service-detector

A Rust crate that provides Windows Service runtime environment detection

1 unstable release

0.1.0 Jun 28, 2023

#527 in #windows

Download history 101/week @ 2024-06-23 42/week @ 2024-06-30 56/week @ 2024-07-07 121/week @ 2024-07-14 92/week @ 2024-07-21 113/week @ 2024-07-28 88/week @ 2024-08-04 94/week @ 2024-08-11 133/week @ 2024-08-18 174/week @ 2024-08-25 55/week @ 2024-09-01 93/week @ 2024-09-08 108/week @ 2024-09-15 154/week @ 2024-09-22 346/week @ 2024-09-29 162/week @ 2024-10-06

778 downloads per month
Used in universal-service

MIT license

8KB
99 lines

windows-service-detector

A Rust crate that provides Windows Service runtime environment detection.

See the documentation library documentation.

Usage

See the provided example in examples/service.rs for a fully functional example.

TL;DR, in your main.rs you should do something like:

use windows_service_detector::is_running_as_windows_service;

fn main() {
    if is_running_as_windows_service().unwrap() {
        run_service();
    } else {
        println!("this is not a service");
    }
}

Running the Example

To demonstrate the example binary running as a normal command line program:

cargo run --example service

To demonstrate the same binary running as a Windows Service, use the provided test script in an Administrator command prompt:

.\example-service-test.ps1

Development

This crate is considered feature-complete, as its sole purpose is to provide Windows Service environment detection.

If you find a bug, please report it through the GitHub issue tracker for this repository.

Dependencies

~129MB
~2M SLoC