Run any program as service in windows

Created: Tue 19 Mar 2024 Updated: 4 months, 1 week ago

article-featured-image

Running a program as a service in Windows can be incredibly useful, allowing you to ensure that critical applications are always running, even if no user is logged in. This capability is particularly valuable for server applications, background processes, and utilities that need to start automatically and run in the background.

In this guide, we will explore various methods to run any program as a service in Windows. We will use NSSM (Non-Sucking Service Manager) and learn the process step-by-step. Whether you're a system administrator looking to manage services more efficiently or a developer needing to ensure your application runs reliably, this guide will help you achieve your goal.

Set up application as service

In this section, we'll set up an application that will be managed as a service. This action will be demonstrated on Nginx web server. I'm using Nginx 1.24.0 version but the same method can be applied if you decide to use another version of it. Download Nginx for windows and follow the below process:

  • Extract Nginx package and place the nginx-1.xx.x folder in "C:\" location.
  • Extract NSSM package and place the nssm-2.xx folder in "C:\" location.
  • Open Powershell in Administrator mode and move to "C:\nssm-2.24\win64" path. nssm.exe named file will be there in this folder, which is an executable to run NSSM application. listing files in nssm folder
  • To install Nginx service, use .\nssm.exe install nginx "C:\nginx-1.24.0\nginx.exe" command. installing nginx service using nssm
  • Start this service using .\nssm.exe start nginx command. starting nginx service in windows 10

To test it, access localhost in your web browser. You'll see Nginx welcome page which indicates that our Nginx service is running. testing nginx server

This service will also be visible in "services.msc" under the name of Nginx. You can use many more options with nssm tool. Use .\nssm.exe --help to get the list of all the available options or you can simply double click the nssm.exe executable file.

Using in GUI mode
To use this application in GUI mode, run the below command:
>
.\nssm.exe install
using nssm in GUI
  • Applications path is, as the name indicates, path to the application.
  • Startup directory is path that is one folder above to the application. For example: If application path is "C:\nginx-1.24.0\nginx.exe" then Startup directory path should be "C:\nginx-1.24.0"
  • Arguments options is additional. You can specify the arguments that are required by your application.
  • Service name is to set the name of service.

You can also explore other options and tweak the service as per your requirement.

Removing service using nssm

To remove the service created using this tool, use the below command:

>
.\nssm.exe stop nginx

>
.\nssm.exe remove nginx

It will stop and remove Nginx service from the system. Make sure to run this command in powershell as Administrator.

Custom service in windows
protocolten-admin

Author: Harpreet Singh
Server Administrator

Suggested Posts:
LINUX post image
Install Latest Version of PHP on CentOS 8 and 7


CentOS is great. I have to admit that all those SELinux enforcement and other …

PROGRAMMING post image
Python Coding Challenge (Level Intermediate)

Python is one of the most powerfull programming language. Python is used in web-development, …

SCRIPTS post image
Create your own personal Secure VPN on the Cloud

This article is about creating a secure personal VPN. Nowadays with all those privacy …

LINUX post image
How to deploy Django application with Nginx, MySQL, and Gunicorn on Ubuntu

Django is an open-source web framework based on Python. It can be very efficient …

LINUX post image
Configure FastAPI with Nginx and uvicorn

This article is all about the configuration of FastAPI with uvicorn and then reverse …

Sign up or Login to post comment.

Sign up Login

Comments (0)