How to Run An Application As Service (Create a User-Defined Service).
If you want to run an application as a Service in Windows OS, then continue reading this tutorial. As you know, the common methods to run a program at Windows Startup is to place the program at Windows Startup folder, or to run the program at startup by using the Windows Registry, or to start the application using the Task Scheduler. Although these methods are effective in most cases, in some cases there is a need to run an application at startup as a Windows service, before user's login or user's interaction.
This tutorial contains step-by-step instructions on how to create a Windows service with any program in Windows 10, 8, 7 & Server OS.
How to Run Any Application as a Windows Service.
Method 1. Run Application as Windows Service by using RunAsService utility.
Method 2. Run Program as Service by using NSSM utility.
Method 1. How to run any application as a Windows Service with 'Run As Service' Utility.
The first method to create a user-defined service from any program is to use the "RunAsService" utility.
1. Download the RunAsService tool to your PC.
2. Move or Copy the downloaded file RunAsService.exe, to the root folder of drive C:\. *
* Note (Important): You can place the "RunAsService.exe" tool to any location you want on the disk, but make sure to keep the tool in the same location in order the installed service(s) to continue functioning.
3. Open Command Prompt as Administrator.
4. In the command prompt type: cd\
5. Now install the application you want as a service, by using the following command: *
- RunAsService install "ServiceName" "Display-Name" "PathToExecutable"
Notes:
1. In the above command replace the values in red letters as follows:
Name: Type a Name for the Service you want to create. You can use the Service Name to start or stop the service manually on the future by giving the "net start" or "net stop" commands.
Display Name: If you want, type a different Name for the Windows Services list. This is how the service name will be displayed in the services list. If no "Display Name" is specified, then the Display Name will be the same as the "ServiceName" of the service you create.
PathToExecutable: Type the full path of the application that you want to run as a Windows service.
For example: To install the "Notepad.exe" application as a Windows service with the name "Notepad", give the following command:
- RunAsService install "Notepad" "C:\Windows\System32\notepad.exe"
Â
2. If after executing the above command you receive the message "An app needs the .Net Framework 2.0 feature to work", click Download and install this feature, or download the .Net Framework 2.0 from the Microsoft download center.
6. After the command execution, a new Windows Service will appear in the services list, with the name you specified in the "RunAsService" command. To run the newly created service at startup:
a. Right-click on the service and choose Properties.
b. Ensure that the Startup type is set to Automatic.
c. Restart your PC, to test the service. *
* Notes:
1. You can start or stop the service at any time you want, by running the "net start" or the "net stop" commands in Command Prompt (Admin).
2. If you want to uninstall the installed service in the future:
a. Stop the service by running this command in Admin Command Prompt:
- net stop "ServiceName"
e.g. net stop "Notepad"
b. Uninstall the service by giving this command:
- RunAsService uninstall "ServiceName"
e.g. RunAsService uninstall "Notepad"
Method 2. How to run any program as a service by using NSSM.
The second method to run any application as a service in Windows, is by using the Non-Sucking Service Manager tool.
1. Download NSSM.
2. Extract the downloaded ZIP file.
3. Rename the extracted folder (e.g. "nssm-2.24"), to NSSM.
4. Copy the NSSM folder to the root folder of drive C:\
5. Open Command Prompt as Administrator and navigate to the NSSM folder, by typing the following commands in order (Press Enter after typing each command):
- cd\
- cd nssm
6. Now according to your Windows version (32 or 64bit), navigate to the one of two contained subfolders, by type the corresponding command (and press Enter).
- If you own 64Bit Windows, type: cd win64
- If you own 32Bit Windows, type: cd win32
7. Now type the following command: *
- nssm install
8. In the window that opens:
8a. Press the tree (3) dots button next to PATH and select the application's executable that you want to run as a service.
8b. When done, type a Name for the new service and click Install service.
8c. Click OK to the message "Service installed successfully" and you're done! *
* Notes:
1. After installing the service with the NSSM service installer, a new Windows Service will appear in the services list, with the name you specified in the Service name, than can be managed as any other Windows service.
2. To uninstall the service in the future:
a. Follow the steps 5 & 6 above, and then type the following command: *
- nssm remove ServiceName
* Note: Where ServiceName = the name of the service you created, using the NSSM utility.
e.g. nssm remove NOTEPAD in this example.
b. Finally click Yes to Remove the service.
That's it! Let me know if this guide has helped you by leaving your comment about your experience. Please like and share this guide to help others.