#windows #service #run-time #detection #environment #running #detector

windows-service-detector

A Rust crate that provides Windows Service runtime environment detection

1 unstable release

0.1.0 Jun 28, 2023

#236 in Windows APIs

Download history 29/week @ 2024-01-09 47/week @ 2024-01-16 73/week @ 2024-01-23 85/week @ 2024-01-30 74/week @ 2024-02-06 88/week @ 2024-02-13 76/week @ 2024-02-20 85/week @ 2024-02-27 130/week @ 2024-03-05 176/week @ 2024-03-12 139/week @ 2024-03-19 76/week @ 2024-03-26 137/week @ 2024-04-02 72/week @ 2024-04-09 64/week @ 2024-04-16 136/week @ 2024-04-23

434 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

~139MB
~2M SLoC