Project 5: A Basic Windows Service
A proper Windows Service that, once installed and started, writes a timestamp to a log file every 30 seconds. The executable will also handle command-line arguments to install and uninstall itself.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C++ |
| Alternative Languages | C |
| Difficulty | Level 2: Intermediate |
| Time Estimate | 1-2 weeks |
| Knowledge Area | Windows Services / OS Integration |
| Tooling | Service Control Manager (SCM) |
| Prerequisites | Project 2, understanding of function pointers. |
What You Will Build
A proper Windows Service that, once installed and started, writes a timestamp to a log file every 30 seconds. The executable will also handle command-line arguments to install and uninstall itself.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Implementing
ServiceMain→ maps to the entry point for the service, where initialization happens - Implementing a Service Control Handler → maps to responding to SCM requests like START, STOP, and PAUSE
- Communicating status to the SCM → maps to using
SetServiceStatusto report state changes - Installing and Uninstalling the service → maps to using
CreateServiceandDeleteServiceAPIs - Debugging a service → maps to the challenge of debugging non-interactive processes
Key Concepts
- Service Lifecycle: “Windows System Programming, 4th Edition” - Chapter 12
- Service Control Manager: Microsoft Docs - SCM Documentation
- Debugging Services: Microsoft Docs - Debugging a Windows Service
Real-World Outcome
# Install the service
> ./my_service.exe install
# Open services.msc and see "My Timestamp Service" listed
# Start it from services.msc or the command line
> sc start MyTimestampService
# Check the log file
> type C:\logs\my_service.log
Service started. Timestamp: 2025-12-21 14:30:00
Service is running. Timestamp: 2025-12-21 14:30:30
Service is running. Timestamp: 2025-12-21 14:31:00
...
# Stop and uninstall the service
> sc stop MyTimestampService
> ./my_service.exe uninstall
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
LEARN_WINDOWS_SYSTEMS_PROGRAMMING_CPP.md - “Windows System Programming, 4th Edition” by Johnson M. Hart