I have the folling problem/situation: My Windows computer runs two programs simultaniously, a backup program and a video converter. Now it shall shut down after all is done. Both programs offer an option to shut down the computer automatically, but of course, the second program would still be running.
Now I know, I could write a program myself which monitors if certain programs are still running (I can tell the to simply close instead of shutting down after doing their stuff).
But, does Windows offer an API for that, like RegisterForShutDown_(), which simply waits until all registered programs are done.
I know this API wouldn't solve my problem with these external programs, I'm just curious.
Manage multiple programs which want to shut down Windows
Manage multiple programs which want to shut down Windows
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: Manage multiple programs which want to shut down Windows
This doesn't really answer the question, but if needed, to avoid auto ShutDown, you can use Sysinternals PsSuspend
To suspend the shutdown:
To resume (it will shutdown if a request has been made previously):
To suspend the shutdown:
Code: Select all
pssuspend64.exe winlogon.exe
pssuspend64.exe wininit.exeCode: Select all
pssuspend64.exe -r winlogon.exe
pssuspend64.exe -r wininit.exeRe: Manage multiple programs which want to shut down Windows
I'm not aware of an API function that will do this in this particular way. You could:
1) If the programs will call a script, create a "lock" file when the tasks begin: "%temp%\lock1.txt" and "%temp%\lock2.txt". Create two batch files which erase their own lock file and look for both "lock" files and run these at the end of the tasks. One of them should exit with a shutdown:
2) If they won't call scripts you could just run the erase command on exit and run the script which looks for the locks for both tasks on a repeating schedule using the task scheduler. It should trigger a shutdown when both files are gone. Don't forget though that this will need to be managed somehow so that it doesn't shutdown the system unexpectedly at other times!
3) If neither of those is suitable you could check out the shutdown api at https://learn.microsoft.com/en-us/windo ... -functions
1) If the programs will call a script, create a "lock" file when the tasks begin: "%temp%\lock1.txt" and "%temp%\lock2.txt". Create two batch files which erase their own lock file and look for both "lock" files and run these at the end of the tasks. One of them should exit with a shutdown:
Code: Select all
erase "%temp%\lock1.txt"
if exist "%temp%\lock1.txt" goto end
if exist "%temp%\lock2.txt" goto end
shutdown /s
:end3) If neither of those is suitable you could check out the shutdown api at https://learn.microsoft.com/en-us/windo ... -functions
Re: Manage multiple programs which want to shut down Windows
Thanks you all, but my question is specifically whether Windows offers something or not.
Following spikeys link tells me there really isn't . Also I assume other developers would have adapted it already.
Though, the function ShutdownBlockReasonCreate_() seems interesting. Maybe a program written by myself to manage the shutdown process is still the best option. For that, monitoring the long running programs should already be enough.
Following spikeys link tells me there really isn't . Also I assume other developers would have adapted it already.
Though, the function ShutdownBlockReasonCreate_() seems interesting. Maybe a program written by myself to manage the shutdown process is still the best option. For that, monitoring the long running programs should already be enough.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD

