Header Ads

How to Convert Any Executable or Batch file to Windows Background Service

When working in software development or deployment environment. Sometimes converting an executable (.exe) tool or a batch file to a windows background service is necessary in order to avoid restarting the whole process again and again manually. This is helpful especially in production servers where in case of abrupt server restart, you don't require to rush into restarting a particular tool or a batch file. The windows background service will do the restarting of your installed service automatically, in case your server or system restarts. So, how can you achieve this?

Today, I shall demonstrate conversion of any executable (.exe) or batch (.bat) file into a windows background service using a powerful yet simple tool NSSM.

 


Prerequisites:

Before proceeding any further in this article, following are some of the many prerequisites for this article:
  1. Download NSSM tool.
  2. Knowledge of Batch (.bat) file.
  3. Knowledge of Windows Command Prompt.

Let's begin now.

1) First step is to download NSSM tool from its official website at your target location.

 
2) In the next step, extract the NSSM tool from the downloaded ZIP file at your target location, make sure to extract your machine's relevant version. I am using windows 64 bit version of NSSM tool for this article.
 
 
3) Now, open Windows Command Prompt as administrator and change into directory location where you have extracted the NSSM tool.

 
4) I have created a sample batch file that simply prints hello world for this article you can check the video demo for details. Now, type below command into windows command prompt for the installation of your windows background service i.e.

 

5) An installation window will appear. Provide relevant configurations within application, details and I/O tab and also enter name of your service and hit install service. You will get a successful installation message. 




6) To confirm that your service is successfully installed as windows background service. Open windows services window by typing below command within run window. Then search for your target service, which in my case is hello world. You can see that my batch file is successfully installed as windows background service. Start the service and make sure that it is in running state because this will confirm that your batch file is working fine. You can check the output in the output log file that you have configured in I/O tab of the NSSM tool during installation.
 
 


 

7) If you which to remove your service then first stop your service from windows services windows. Next, open the windows command prompt window as administrator and type below command with your service name. A confirmation message will appear. Click yes and you will receive a successful removal message. Refresh windows service window and you can see that your service is no longer available on your machine.

 


 

Conclusion

In this article, you will learn to convert any executable (.exe) or batch (.bat) file to windows background service using a simple yet powerful tool called NSSM. You will learn the entire installation process that includes installation and verification of your service. You will also learn to verify your successful windows service installation through windows services window. Finally, you  will learn to remove your service through NSSM tool.
 

Related Articles


Video