Many of us have at least one PC that's assigned mainly to running MyHD, CW_EPG, and maybe FusionHDTV to schedule and capture HDTV shows. Such HTPCs don't need to run 24/7, since they can easily be waked from S4 (hibernation) to perform scheduling and captures and then go back to sleep, saving over 90% of the energy that would be wasted by running them all the time in most cases.
The best way to have them go back to sleep is via Windows' Power Options inactivity timeout, which can be set to hibernate (or suspend) the PC after a specified period without any application or user interactions. The rub is that sometimes (far too often) there is an application or service that inhibits Power Options from its timeout action.
Inspired by
Dale's brilliant idea above, I devised the below batch file to take a more forceful approach to the shutdown process without interfering with MyHD, FusionHDTV, or CW_EPG functions. This batch file is invoked via the Start|Programs|Startup menu. (Set the shortcut's properties to run minimized so that you don't have a stray window open on your desktop--a refinement to this would be to use a Windows script plus the technique that runs scripts without a visible window--See Dave Plettner's post just below for a link describing how to do this) Then the batch file runs continuously, checking every 10 minutes when the PC is not sleeping, to see if one of the designated apps is running and, if not, it sends the PC back to sleep. Obviously, you can add other "must run" apps to fit your situation. The main downside of this approach is that the PC will fail to go to sleep if you inadvertently leave one of those apps running. (But that's probably what would happen anyway with Power Options, so it's not a new problem)
EDIT: I've enhanced this batch file to also check for Dr. Watson's running (waiting for you to allow him to phone MSFT about the crashed app) and then initiate a restart. This is my approach to the enhancement that Dave Plettner suggested below for handling this situation.
PoormansPowerOptions.bat
Code:
@echo off
:loop1
rem first wait 10 minutes...
ping -n 600 127.0.0.1>nul
rem Done waiting!
set pid=na
rem next chk for hung apps (with dr watson asking to phone MSFT)
for /f "tokens=1" %%a in ('tlist.exe ^| find /i "dwwin.exe"') do set pid=%%a
if not "%pid%"=="na" SHUTDOWN -r -f
rem no hung app, so continue
rem chk for CW_EPG, MyHD, or FusionHDTV running
for /f "tokens=1" %%a in ('tlist.exe ^| find /i "MyHD.exe"') do set pid=%%a
for /f "tokens=1" %%a in ('tlist.exe ^| find /i "FusionHDTV.exe"') do set pid=%%a
for /f "tokens=1" %%a in ('tlist.exe ^| find /i "CW_EPG.exe"') do set pid=%%a
if not "%pid%"=="na" GOTO NOSHUTDOWN
rem pid was not found so we can shut down without harm.
start hibernate(neverforce).exe
:NOSHUTDOWN
rem Do nothing now, since must-run app is on %pid%
Goto loop1
To run this batch file, you'll also need to copy the NT SDK applet tlist.exe (
This MSFT KB article describes one source--Google will provide others) and a suitable "hibernate.exe" (e.g., from
here) to a folder on your PATH, such as the Windows system folder.
EDIT2: I have further streamlined Poorman's Power Options in a Windows XP-specific version that does not require any 3rd-party downloads to implement. Its function is still the same and it's best invoked via the Startup folder in the Start Programs menu so that it runs automatically at each boot up. Here's the new version:
Poorman's Power Options for Windows XP only:
Code:
@echo off
:loop1
rem first wait 10 minutes...
CALL sleep 600
rem Done waiting!
rem Now chk for hung apps (with dr watson asking to phone MSFT)
for /f "tokens=1" %%a in ('tasklist ^| find /i "dwwin.exe"') do SHUTDOWN -r -f -c "PPO found crash-hung app"
rem no hung app, so continue
rem Finally, chk for must-run apps
for /f "tokens=1" %%a in ('tasklist ^| find /i "MyHD.exe"') do GOTO loop1
for /f "tokens=1" %%a in ('tasklist ^| find /i "FusionHDTV.exe"') do GOTO loop1
for /f "tokens=1" %%a in ('tasklist ^| find /i "CW_EPG.exe"') do GOTO loop1
rem Must-run apps not found, so we can sleep without harm.
start %SystemRoot%\\system32\\RunDll32.exe powrprof.dll,SetSuspendState
rem But stay on the job!
Goto loop1
Sleep.bat:
Code:
rem delay for %1 seconds
ping -n %1 127.0.0.1>nul
EDIT3: I think that the RunDll32.exe method of hibernating inhibits the following scheduled wake up, at least on some PCs some of the time.

If you find this happening to you, try the hibernate(neverforce).exe referenced in the first batch file version instead.
Further clarification rendered via Google: Evidently this problem has to do with the fact that RunDll32.exe is not properly used to call the SetSuspendState entry point in powrprof.dll, despite this tip's being widely found on the Internet. (See "How do I inflate a bicycle tire with a potato?" and links for detailed explanation)EDIT4: BTW, I should also mention that the problem of inhibiting scheduled wake-up events also seems to exist in the SysInternals PSshutdown tool.