Automatically create and manage Windows services for Python scripts with zero configuration required.
Windows Service Creator is a powerful Python automation tool that simplifies the process of creating Windows services from Python scripts. With a single command, transform your main.py script into a fully-functional Windows service with automatic restart, logging, and service management capabilities.
- Zero-configuration setup - automatically detects script location, working directory, and Python interpreter
- Intelligent naming - uses current folder name as service identifier
- Smart defaults - production-ready configuration out of the box
- Auto-restart on failure - ensures your service stays running 24/7
- Configurable restart delays - prevents rapid restart loops
- Automatic startup - service starts automatically when Windows boots
- Graceful error handling - comprehensive error management and reporting
- Automatic log file creation - separate stdout and stderr logs
- Log rotation support - prevents disk space issues with 10MB rotation
- Real-time monitoring - easy access to service output and errors
- Journal-style logging - similar to Linux systemd journal
- NSSM integration - uses Non-Sucking Service Manager for reliability
- Auto-download capability - fetches NSSM automatically if not installed
- Administrator privilege detection - prevents permission-related errors
- Service conflict detection - handles existing service scenarios gracefully
- Windows 7/8/10/11 or Windows Server 2012+
- Python 3.6 or higher installed and added to PATH
- Administrator privileges required for service installation
# Clone the repository
git clone https://github.com/thenik/service-windows-create.git
cd service-windows-create
# Install Python dependencies
pip install pywin32
# Run the service creator (as Administrator)
python service_windows_create.pyThe script automatically downloads NSSM, but you can install it manually:
# Download from https://nssm.cc/download
# Extract and add to PATH or place in script directory-
Navigate to your Python project directory containing
main.py:cd C:\path\to\your\project
-
Run the service creator as Administrator:
python service_windows_create.py
-
Service is automatically created, configured, and started
After installation, manage your service with these Windows commands:
# Check service status
sc query your_service_name
# Start the service
net start your_service_name
# Stop the service
net stop your_service_name
# Restart the service
net stop your_service_name && net start your_service_name
# Remove the service
nssm remove your_service_name confirmEdit service settings using NSSM GUI:
nssm edit your_service_nameOr access Windows Services Manager:
services.mscThe service is automatically configured with these settings:
| Setting | Default Value | Description |
|---|---|---|
| Script Path | ./main.py |
Python script to run as service |
| Working Directory | Current folder | Service execution directory |
| Python Interpreter | sys.executable |
Active Python interpreter path |
| Service Name | Folder name | Windows service identifier |
| Startup Type | Automatic | Service starts with Windows |
| Restart Delay | 5 seconds | Time between restart attempts |
| Log Location | ./logs/ |
Service output log directory |
| Log Rotation | 10 MB | Maximum log file size before rotation |
Access service logs in the automatically created logs directory:
# View standard output
type logs\your_service_name_stdout.log
# View error output
type logs\your_service_name_stderr.log
# Monitor logs in real-time (PowerShell)
Get-Content logs\your_service_name_stdout.log -Wait -Tail 50Logs automatically rotate when they reach 10MB, preventing disk space issues. Older logs are archived with timestamps.
Solution: Right-click Command Prompt or PowerShell and select "Run as administrator"
Solution: The script will prompt to remove and recreate the service, or manually remove it:
nssm remove your_service_name confirmSolution: Check error logs in logs\your_service_name_stderr.log and verify:
- Python script has no syntax errors
- All dependencies are installed
- File paths are correct
Solution: Manually download NSSM from nssm.cc and place in script directory
This tool provides Windows equivalents for systemd features:
| systemd Feature | Windows Equivalent |
|---|---|
systemctl enable |
Automatic startup configuration |
systemctl start |
Service start via NSSM |
Restart=on-failure |
Auto-restart on exit codes |
RestartSec=5 |
5-second restart delay |
journalctl |
File-based logging with rotation |
/etc/systemd/system/ |
Windows Service Manager |
- Test your Python script thoroughly before creating the service
- Use virtual environments - point to the venv Python executable
- Configure proper logging in your application
- Set appropriate restart policies based on your use case
- Monitor service health regularly using Windows Event Viewer
- Run services with least privilege accounts when possible
- Store sensitive credentials in Windows Credential Manager
- Enable Windows Firewall rules if service uses network ports
- Regularly update dependencies for security patches
- Minimize startup time for faster service recovery
- Implement graceful shutdown handlers in your script
- Use connection pooling for database services
- Monitor resource usage via Task Manager or Performance Monitor
your-project/
├── main.py # Your Python application
├── service-windows-create.py # Service creator script
├── logs/ # Auto-generated log directory
│ ├── your_service_name_stdout.log # Standard output
│ └── your_service_name_stderr.log # Error output
└── nssm/ # Auto-downloaded NSSM (if needed)
└── nssm.exe
- Python: 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12
- Operating System: Windows 7/8/10/11, Windows Server 2012+
- Dependencies: pywin32
- Privileges: Administrator access required
- Architecture: x86 (32-bit) and x64 (64-bit) supported
Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest new features.
# Fork and clone the repository
git clone https://github.com/thenik/service-windows-create.git
# Create a feature branch
git checkout -b feature/your-feature-name
# Make changes and test thoroughly
# Submit a pull requestThis project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Full documentation
- Issues: Report bugs
- Discussions: Community forum
windows service, python service, windows automation, systemd windows, service manager, python windows service, automatic service creation, nssm python, windows service installer, python daemon windows, background service windows, python script service, windows service wrapper, auto restart service, python service manager
Made with ❤️ for Python developers who need reliable Windows services