I have some programs that take a while to run and I would like to have my computer shut down after they have run. (Only one would be running at the time)
I have code to shutdown my computer.
I was thinking I could either:
1. Add some timer code that would just shutdown after a fixed amount of time
2. The program uses 90+ % of the CPU when it's running (Is there a way to monitor
the usage so I can I check when it's usage has gone down to say 5% and then trigger a shutdown ?)
Thanks.
If your program launches the others, then you can just wait for them to exit -- if (GetExitCodeProcess != STILL_ACTIVE) ExitWindows(EWX_SHUTDOWN,0);
I manually start it. I'll check to see if there is a command line way to launch it. Would GetExitCodeProcess work with that situation ?
Two other ways to check.
If the program with high CPU use creates a file or deletes a file just before ending
that could be tested for, or if the program could be run as part of a batch file
you could have a second short program write a file or even have the second
program be the shutdown program.
If the program has a GUI, the titlebar text could be checked for every minute or so
when it no longer is found the shutdown could be done.
Okay then, quick solution..
Create an exe that causes shutdown when run (does nothing else.)
Then do a batch file:
@echo off
echo Doing stuff...
your_program_that_does_stuff.exe
maybe_another_program_that_something.exe
echo Shutting down.
your_shutdown_exe
Create a mutex and when the process is done, release the mutex.
Then have the shutdown code watch the mutex, then execute.
Regards, P1 :8)