With the help of the task scheduler and the Windows PowerShell, services and processes can be terminated in a time-controlled manner.
There are many reasons why a specific process or service must be terminated: Performing a consistent data backup or restarting a service at a specific time.
A recurring case from my practice is, for example, the application CodeTwo Email Signatures in combination with a Windows terminal server. The client, which reliably imports the signatures into the user profiles, can only be run by one user at a time on the terminal server. This means: whoever logs in first will receive the current signature changes. Everyone else doesn’t because the process is already in use. Here I help myself to end the process with the PowerShell time-controlled. This is then available again for the next logins.
The command to kill a process is stop process. The complete command to exit (e.g., from Microsoft Outlook) is:
Stop-Process -Name Outlook
In combination with the Windows task scheduler, the whole thing looks like this:
In this way, processes can be terminated to the second. For example, in the example above, I automatically terminate the Email Signatures with a one-minute delay at each user login. This period of time is sufficient to update the signatures before the process is terminated again.
If the processes of other users are to be terminated, the parameter -force to add. This suppresses the prompt before exiting. If this parameter is missing, the task will not be completed because PowerShell waits for input in the background.
The full command would then be:
Stop-Process -Name Outlook -force
To be able to terminate processes in a time-controlled manner, no complicated scripts are required. The starting of processes is also included start process possible.
Important: The example above kills ALL processes with the given name. On systems where multiple users are logged on, all active users’ processes of the same name would be terminated. Here it is recommended to use the command with the parameter -ID instead of -Name and to specify the corresponding process ID.