How To Create a Windows Service

We’re not talking buckets and squeegees

Sometimes you need an app or script to keep running whether you’re logged into your computer or not. Maybe it’s aPowerShell script to monitor portsor aweb server hosting a page on your home network.

The point is that if you want a process, script, or program to run as long as the computer is on, you’ll need to create a Windows Service.

What Do I Need to Create a Windows Service?

To create a Windows service in Windows 10, there are a few prerequisites:

What Is the Non-Sucking Service Manager?

Yes, you can’t drop a name like that without explaining it. Sure the name is unfortunate, yet it is accurate. The Non-Sucking Service Manager (NSSM) is arguably the easiest way to create a Windows service that is both highly reliable and configurable. Plus, it’s free andOpen Source Software(OSS).

NSSM can be used through the Windows Command Prompt, or a graphical user interface (GUI). This means anyone can use it. NSSM can be used on any version of Windows going back to, and including, Windows 2000. There are32-bit and 64-bitversions. If you’re using a 64-bit computer, try that version first. If it doesn’t work, fall back to the 32-bit version.

You candownload NSSM from the website,clone NSSM from Git, orinstall NSSM with Chocolatey.Chocolatey is a package manager for Windows. Installation methods will vary depending on which route you take. Please consult NSSM’s instructions. For our example, we’re downloading from the NSSM website and installing it inC:WINDOWSsystem32.

Create a Windows Service With NSSM

For this example, we’ll create a service out of aPowerShell scriptto logCPU average load percentage.

Note: All lines below followed by the # symbol are comments and won’t affect the script.

There are several other tabs that can be used to customize the service. For this exercise, the default values in those tabs are sufficient. Select theInstall servicebutton.

nssm-check-log.png

Removing a Windows Service With NSSM

Maybe you don’t need tomonitor your CPUload anymore, so you’d like to get rid of the service. Fortunately, NSSM makes that easy.

That’s all. It’s a good idea to check the services manager to ensure the service is no longer there. If you still see the service, you may need to refresh the screen and it should be gone.

Services are a great way to run apps or scripts that need to run all the time, restart themselves if they fail, or need privileges different from the current user. If you don’t need your app or script to do all of those things, considerusing a Scheduled Taskinstead.

Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches.Read Guy’s Full Bio

Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.

HomeAbout UsEditorial StandardsContact UsTerms of Use

Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved