Davasorus.Utility.DotNet.Services 2026.2.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Davasorus.Utility.DotNet.Services --version 2026.2.1.3
                    
NuGet\Install-Package Davasorus.Utility.DotNet.Services -Version 2026.2.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Davasorus.Utility.DotNet.Services" Version="2026.2.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Davasorus.Utility.DotNet.Services" Version="2026.2.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Davasorus.Utility.DotNet.Services" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Davasorus.Utility.DotNet.Services --version 2026.2.1.3
                    
#r "nuget: Davasorus.Utility.DotNet.Services, 2026.2.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Davasorus.Utility.DotNet.Services@2026.2.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Davasorus.Utility.DotNet.Services&version=2026.2.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Davasorus.Utility.DotNet.Services&version=2026.2.1.3
                    
Install as a Cake Tool

Davasorus.Utility.DotNet.Services

Davasorus.Utility.DotNet.Services provides a set of service/client abstractions for managing Windows services (start, stop, load, manipulate) in .NET 8+ applications. It is designed for use with dependency injection (DI). End users should only interact with the service interfaces; the services handle all client interactions, error handling, and logging.

Note: Only interact with the service interfaces (e.g., IStartServiceService, IStopServicesService, ILoadServicesService, IManipulateServiceService) in your application code. The service classes manage all communication with their respective client classes internally.

Features

  • Start, stop, and manipulate Windows services on remote or local hosts
  • Retrieve service lists and descriptions, with streaming support
  • Strongly-typed async APIs
  • OpenTelemetry distributed tracing via ActivitySource on all operations
  • Robust error handling and logging (ILogger + SQS integration)
  • Designed for DI: Service = Scoped, Client = Transient

Dependency Injection Setup

Register all services using the AddWindowsServices() extension method:

using Tyler.Utility.DotNet.Services.Configuration;

services.AddWindowsServices();

This registers the following services automatically:

Interface Implementation Lifetime
IStartServiceService StartServiceService Scoped
IStartServiceClient StartServiceClient Transient
IStopServicesService StopServicesService Scoped
IStopServicesClient StopServicesClient Transient
ILoadServicesService LoadServicesService Scoped
ILoadServicesClient LoadServicesClient Transient
IManipulateServiceService ManipulateServiceService Scoped
IManipulateServiceClient ManipulateServiceClient Transient

Example Usage

Start a Service

public class MyServiceStarter
{
    private readonly IStartServiceService _startService;
    public MyServiceStarter(IStartServiceService startService)
    {
        _startService = startService;
    }

    public async Task StartAsync(string host, string serviceName)
    {
        await _startService.StartService(host, serviceName);
    }
}

Stop a Service

public class MyServiceStopper
{
    private readonly IStopServicesService _stopService;
    public MyServiceStopper(IStopServicesService stopService)
    {
        _stopService = stopService;
    }

    public async Task StopAsync(string host, string serviceName)
    {
        await _stopService.StopService(host, serviceName);
    }
}

Load Services List

public class MyServiceLoader
{
    private readonly ILoadServicesService _loadService;
    public MyServiceLoader(ILoadServicesService loadService)
    {
        _loadService = loadService;
    }

    public async Task<List<ServiceObj>?> GetServicesAsync(string host)
    {
        return await _loadService.GetServiceList(host);
    }
}

Manipulate Service State

public class MyServiceManipulator
{
    private readonly IManipulateServiceService _manipulateService;
    public MyServiceManipulator(IManipulateServiceService manipulateService)
    {
        _manipulateService = manipulateService;
    }

    public async Task<bool> EnableServiceAsync(string host, string serviceName)
    {
        return await _manipulateService.SetSpecifiedServiceOnMachineToEnabled(host, serviceName);
    }
}

API Overview

IStartServiceService

  • Task StartService(string hostName, string serviceName, TimeSpan? timeout = null) Starts the specified Windows service on the given host. Defaults to 60 seconds if no timeout is specified.

  • Task StartWebServices(string hostName, TimeSpan? timeout = null) Starts all web-related Windows services on the specified host. Defaults to 30 seconds if no timeout is specified.

IStopServicesService

  • Task StopService(string hostName, string serviceName, TimeSpan? timeout = null) Stops the specified Windows service on the given host. Defaults to 60 seconds if no timeout is specified.

  • Task StopWebServices(string hostName, TimeSpan? timeout = null) Stops all web-related Windows services on the specified host. Defaults to 30 seconds if no timeout is specified.

ILoadServicesService

  • Task<List<ServiceObj>?> GetServiceList(string hostName) Retrieves a list of Windows services from the specified host. Returns a list of ServiceObj instances representing each service, or null if retrieval fails.

  • Task<string> GetServiceDescription(string hostName, string serviceName) Gets the description of a specific Windows service on the given host. Returns the service description as a string.

  • IAsyncEnumerable<ServiceObj> GetServiceListStreaming(string hostName) Streams Windows services from the specified host as they are discovered. Returns an async stream of ServiceObj instances.

IManipulateServiceService

  • Task<bool> SetSpecifiedServiceOnMachineToEnabled(string hostName, string serviceName) Enables the specified Windows service on the given host, setting its startup type to "Automatic". Returns true if successful.

  • Task<bool> SetSpecifiedServiceOnMachineToDisabled(string hostName, string serviceName) Disables the specified Windows service on the given host, setting its startup type to "Disabled". Returns true if successful.

  • Task<bool> SetSpecifiedServiceOnMachineToManual(string hostName, string serviceName) Sets the specified Windows service on the given host to "Manual" startup type. Returns true if successful.

Error Handling

All errors are logged via ILogger and reported to SQS. Service methods return null, false, or the exception message as appropriate, and log details for diagnostics. All operations are instrumented with OpenTelemetry ActivitySource spans for distributed tracing.

Requirements

  • .NET 8.0 or later

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.2.3.1 0 6/1/2026
2026.2.2.14 36 5/31/2026
2026.2.2.13 91 5/23/2026
2026.2.2.12 96 5/19/2026
2026.2.2.11 93 5/18/2026
2026.2.2.10 97 5/18/2026
2026.2.2.9 87 5/18/2026
2026.2.2.8 90 5/17/2026
2026.2.2.7 94 5/17/2026
2026.2.2.6 99 5/17/2026
2026.2.2.5 88 5/17/2026
2026.2.2.4 84 5/16/2026
2026.2.2.3 88 5/16/2026
2026.2.2.2 95 5/16/2026
2026.2.2.1 94 5/15/2026
2026.2.1.3 149 4/16/2026
2026.2.1.2 2,180 4/9/2026
2026.2.1.1 344 4/1/2026
2026.1.3.5 153 3/29/2026
2026.1.3.4 186 3/29/2026
Loading failed