-2

I would like to put my PC into standby if a specific program is manually stopped. If possible I would like a timeout to allow me to restart the program before the standby is activated.

Is this possible?

Many thanks.

Paul
  • 443
  • 8
  • 18
  • You could write a PowerShell that checks currently running processes and if the one you're interested in is missing (or `Process.WaitForExit()`), starts a timer, pops up a message box and after the timer elapses, puts your pc in standby. Put that in the Task Scheduler to like run every minute. Now if it works, you have a new problem: if you wake your computer from standby, the script will run again and put your machine back in standby. Also, an administrative user could simply stop the task. Anyhow, read [ask], everything is possible, but with what part specifically do you need help? – CodeCaster Nov 26 '21 at 10:43
  • No. The supported scenario is that a program *prevents* standby. When it stops running then it can no longer do this and the machine may shut down. SetThreadExecutionState() in the winapi. – Hans Passant Nov 26 '21 at 11:35
  • Many thanks for the reply. I have never used Powershell, good excuse to learn how to use it. Yes, I could check the list of active processes, and if the one for my program is missing, start the procedure to put the PC into standby. Waking from standby can be handled by checking if the program is not running, and using the same timeout mechanism to give me the opportunity to start the program before the timeout. – Paul Nov 26 '21 at 12:42
  • I've managed to implement this using the TaskScheduler and the PowerShell. In principle it works, and it displays the popup when the program has been stopped. However, the task scheduler also displays the PowerShell window every minute, I would like it to run silently and only display the popup when necessary without the PoiwerShell window. I've Googled this, and I haven't been ablem to find a solution that can be combined with the TaskScheduler. – Paul Nov 28 '21 at 17:34

1 Answers1

0

As I mentioned in the comment, the solution is to use use a Powershell script. However, as noted the popup does not display if the PowerShell script is executed by the Task Scheduler. The solution is to wrap the PowerShell script in a Visual Basic wrapper script, as described here, and call the VBS script from the Task Scheduler. Not an elegant solution. Give me a Linux cron job anyday...

Paul
  • 443
  • 8
  • 18