Powershell – Disable Windows 10 Service on PC Unlock

My Issue

Recently I was running on a computer with a policy that was starting a (clearly) malfunctioning program on start-up which basically permanently was taking 100% of my CPU.

I didn’t have the ability to change the policy, but I did have the ability to stop the service.  Unfortunately, it regularly gets brought back as manually enabled and started.

The Fix

In cases like this, on Windows 10, you can search “Task Scheduler” on your start menu.  Then create a new task (not a basic task) that runs with highest privileges.  You can tell it to trigger on PC unlock, and have it start a program.

For the program, you can give your path to powershell (e.g. C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe).  Then you can give the parameters “-windowstyle hidden C:\dev\disable-service.ps1”.  Honestly, the window style hidden isn’t working but since it just runs on unlock its not a big deal; I’ll figure that out later.

The disable-service.ps1 script should have content like this:

Set-Service "Your Service Name" -StartupType Disabled
Stop-Service "Your Service Name"

You can get the full service name from your services utility in Windows. Note that the real service name needs to be used, and that may not be what you see specifically in the services utility or task manager. But if you click on the service in the services utility, you can get this real name easily.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s