Manage Window Service Over Remote Server using Web API

It’s happened that we need to maintain Windows services running on different remote servers for different environments and we need to remember all their credentials respectively.

As a concerned person or IT infra person keeps those tracks we need to ask them to start/stop the service while doing any deployment, server maintenance, data migration, or any other process.

It’s been tedious to handle those services remotely and keep on disturbing a team or person to help you out in such situations.

Instead of being a person who manages those services, why don’t we provide a tool or functionality to get this work done by every authorized individual!!

Here we are developing a web API that can Start/Stop/Retrieve the Status of a window service running on a remote Server, considering we should have credentials or access rights to respective servers. Such API can be consumed or used in any application to set functionality to handle those services remotely.

Create a Web API in C#

Create a Web API Project in C#, in here we are working on three operations with regards to window service.

  1. Fetching status of a service.
  2. Start window service.
  3. Stop window service.
    Service worker

Code for retrieving the status of the window service.

Status of window

Output

Response

Code to start window service.

Code to start

Output

Curl

Code to stop window service.

Code  to stop window service

Output

Responses

To summarize, we can save time by avoiding login to remote servers to start/stop all those services by clicking one button and can monitor the service’s status using such functionality.