The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: skywalker on August 31, 2006, 08:26:23 AM

Title: Timed shutdown
Post by: skywalker on August 31, 2006, 08:26:23 AM
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.
Title: Re: Timed shutdown
Post by: Tedd on August 31, 2006, 10:29:07 AM
If your program launches the others, then you can just wait for them to exit -- if (GetExitCodeProcess != STILL_ACTIVE) ExitWindows(EWX_SHUTDOWN,0);
Title: Re: Timed shutdown
Post by: skywalker on August 31, 2006, 09:16:46 PM
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 ?

Title: Re: Timed shutdown
Post by: dsouza123 on September 01, 2006, 01:39:03 AM
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.
Title: Re: Timed shutdown
Post by: Tedd on September 01, 2006, 10:35:49 AM
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

Title: Re: Timed shutdown
Post by: P1 on September 01, 2006, 01:23:29 PM
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)