A proof-of-concept Windows service written in Rust, using no third-party service wrapper libraries — only the official windows crate published by Microsoft.
The goal was to answer a simple question: What would it actually look like to implement a Windows service in Rust without relying on a library to abstract the Service Control Manager (SCM) API?
Most Rust Windows service examples reach for crates like windows-service. This project deliberately avoids that, calling the raw Win32 service APIs directly to understand exactly what the SCM expects and how the service lifecycle works at the API level.
The service runs in the background and writes a Unix timestamp to C:\Windows\Temp\service.log once per minute. Simple by design — the point is the plumbing, not the payload.
Builds a null-terminated SERVICE_TABLE_ENTRYW array and passes it to StartServiceCtrlDispatcherW. This hands execution over to the SCM, which then calls service_main on a new thread.
The function the SCM invokes. It must be #[no_mangle] unsafe extern "system" to satisfy the calling convention and symbol name requirements. It:
- Registers
service_control_handlerwithRegisterServiceCtrlHandlerExW - Reports
SERVICE_RUNNINGto the SCM viaSetServiceStatus - Loops in 1-second sleep increments, writing a timestamp every 60 seconds
- Reports
SERVICE_STOPPEDon exit
Sleeping in 1-second increments (rather than one 60-second sleep) keeps the service responsive to stop signals without needing synchronization primitives like condvars or channels.
Called by the SCM when a control code is received (e.g., from sc stop or the Services UI). On SERVICE_CONTROL_STOP, sets a global AtomicBool that causes the main loop to exit cleanly.
[dependencies]
windows = { version = "0.48.0", features = [
"Win32_Foundation",
"Win32_System_Services"
] }No other dependencies.
Requires a Windows target and the MSVC toolchain:
cargo build --release --target x86_64-pc-windows-msvcRegister the service with the SCM (run as Administrator):
sc create SuperSimpleRustService binPath= "C:\path\to\super_simple_rust_service.exe"
sc start SuperSimpleRustServiceStop and remove it:
sc stop SuperSimpleRustService
sc delete SuperSimpleRustService