Managing Windows Services and Process Supervision

Windows Service Management

To access the Windows Services interface, execute the following command:

services.msc

For comprehensive understanding of Windows internals including sessions, window stations, and desktops, refer to: Understanding Windows at a Deeper Level.

Creating Custom Windows Services

To register a new Windows service, use the SC command-line utility. For example, to create a folder monitoring service:

sc create monitor binpath= "D:\\Software\\OtherTool\\MonitorFolder.exe --service -r D:\\Software\\OtherTool" displayname= "Folder Monitor" start= auto

Note the spaces after each equals sign. Upon successful execution, you'll receive confirmation: [SC] CreateService SUCCESS.

Process Supervision with Supervisord

Supervisord provides robust process management capabilities on Windows systems.

Repository: https://github.com/ochinchina/supervisord

Installation

go build -o supervisord.exe

Place the executable in your GOPATH/bin or system PATH. Verify installation:

supervisord version

Sample Application Setup

Create a simple web service for demonstration:

package main

import "github.com/gin-gonic/gin"

func main() {
    router := gin.Default()
    router.GET("/", func(ctx *gin.Context) {
        ctx.String(200, "healthy")
    })
    router.Run(":7111")
}

Build the application:

go build -o main.exe

Configuration Files

Create the main configuration file at E:\\etc\\supervisord.conf:

[inet_http_server]
port=127.0.0.1:9001

[include]
files = E:\\etc\\supervisord.d\\*.ini

Create program configuration at E:\\etc\\supervisord.d\\app.ini:

[program:web_service]
directory=G:\\workspace\\project
command=G:\\workspace\\project\\main.exe
stdout_logfile=G:\\workspace\\project\\output.log
stdout_logfile_backups=50
redirect_stderr=true
autostart=true
autorestart=true

Execution

supervisord -c E:\\etc\\supervisord.conf -d

Verify operation by accessing localhost:7111 in your browser.

Non-Sucking Service Manager (NSSM)

NSSM provides reliable service management without the limitations of traditional tools like srvany.

Official documentation: http://nssm.cc/commands

Basic Operations

Install NSSM by extracting the distribution archive and placing nssm.exe in your system PATH.

# Install new service
nssm install myservice "C:\\path\\to\\application.exe"

# Start service
nssm start myservice

# Check service status
nssm status myservice

# Stop service
nssm stop myservice

# Remove service
nssm remove myservice

Advanced Configuration Example

nssm remove monitoring_agent
nssm install monitoring_agent "D:\\agent\\windows-collector.exe"
nssm set monitoring_agent DisplayName "System Monitoring Agent"
nssm set monitoring_agent Description "Performance data collector"
nssm set monitoring_agent AppDirectory "D:\\agent"
nssm set monitoring_agent AppStdout "D:\\agent\\collector.log"
nssm set monitoring_agent AppParameters "--config config.json"
nssm set monitoring_agent Start SERVICE_AUTO_START
nssm start monitoring_agent

Key Features

  • Automatic process monitoring and restart capability
  • Support for both console and GUI applications
  • Configurable output redirection with log rotation
  • Enviroment variable customization
  • Simple installation and modification process

Service Management Commands

nssm install <service_name>           # Install service
nssm remove <service_name>            # Remove service
nssm edit <service_name>              # Modify service properties
nssm start <service_name>             # Start service
nssm stop <service_name>              # Stop service
nssm restart <service_name>           # Restart service

File Integrity Verification

To calculate MD5 checskum of files on Windows:

certutil -hashfile <filepath> MD5

Tags: Windows services supervisord nssm process-management

Posted on Thu, 08 Oct 2026 16:40:25 +0000 by defect