Security, PKI, sys and network admins

How to schedule Windows processes/applications to stop/shutdown via PowerShell

How to schedule Windows processes/applications to stop/shutdown via PowerShell

I wanted to schedule turning off/shutting down Windows processes/applications because as time passes during my day at my computer, I open more and more applications and they get crowded in my workspace. This is why, I decided to create a PowerShell script that I would execute as soon as I’ve opened my computer. A form of a scheduler that stops applications while I’m working at my computer.

And the script is a pretty easy one. Basically, the script consists of 2 commands: one command that tells the script to “wait” X seconds and a 2nd command that will actually stop/shutdown the Windows process/application that you need.

  1. Create a file name of your choosing but with a .ps1 extension. For example: close_processes.ps1.
  2. Inside it, use the Start-sleep command, along with the -s will tell the script to wait 10 seconds before the next command:
Start-Sleep -s 10
  1. If you’re not sure the name of your running process for your Windows applications, you have to get a list of all active/running processes on your Windows machine.
  2. The Stop-process command will now close a running Windows process/application. In the example below, we’ll decide to close uTorrent, 10 seconds after I will run the close_processes.ps1 script. It’s pretty useful for me whenever I need to schedule Windows services to be closed, especially when I’m late in the night, almost in a nice limbo state of remote work and forget to close windows I’m not using anymore so that I can relieve some hardware resources.
Stop-Process -Name uTorrent

We can also stop a even more diverse range of Windows processes, like the popular FileZilla, Chrome web browser, VLC player, Microsoft Edge web browser. But we can also close them, one by one or in groups, at different times. In the example below, I’ll:

  1. stop the uTorrent Windows application after 2h (which is 7200 seconds) of using it;
  2. stop Microsoft ScreenSketch, Slack, Microsoft Teams after 9h (which is 32400 seconds);
Start-Sleep -s 7200
Stop-Process -Name uTorrent
Start-Sleep -s 32400
Stop-Process -Name ScreenSketch
Stop-Process -Name filezilla
Stop-Process -Name chrome
Stop-Process -Name vlc
Stop-Process -Name msedge

Once you’ve finished writing your own PowerShell scheduler, you’ll need to run the script.

How to schedule Windows processes/applications to stop/shutdown via PowerShell
How to schedule Windows processes/applications to stop/shutdown via PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *