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:
Administrator access on the computerSomething to run as a service (PowerShell Script, program, etc.)Non-Sucking Service Manager (NSSM) installed
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 and Open 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 are 32-bit and 64-bit versions. 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 can download NSSM from the website, clone NSSM from Git, or install 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 in C:\WINDOWS\system32.
Create a Windows Service With NSSM
For this example, we’ll create a service out of a PowerShell script to log CPU 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 the Install service button. nssm-check-log.png
Removing a Windows Service With NSSM
Maybe you don’t need to monitor your CPU load 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, consider using a Scheduled Task instead.