Preventing Automatic Power Off

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am trying to prevent the device from auto powering off. I tried the
following code on a device that is running PPC 2002, it works fine but when
I tried it on a device running Windows Mobile 2003 OS, it is not working
correctly.

1. The Get option always returning 0

2. The set option is always failing.

My sample code is below:

void
CSystemParameters::SetSystemTimouts(DWORD iSecs)
{
DWORD batIdle, acIdle, wakeUpIdle, shortestIdle;
TCHAR szOutput[200];

// get the values
SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&batIdle,0);
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT,0,&wakeUpIdle,0);

// determine which is the lowest non-zero value
shortestIdle=batIdle;
shortestIdle=((acIdle>0)&&(acIdle<shortestIdle)) ? acIdle :
(((wakeUpIdle>0)&&(wakeUpIdle<shortestIdle)) ? wakeUpIdle : shortestIdle);

if (shortestIdle==0)
// if all values are zero, the device will never timeout
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout:
%d\nWakeup Idle Timeout: %d\nThe device will not timeout."),batIdle, acIdle,
wakeUpIdle);
else
{
// otherwise, you need to reset the idle timer more
// frequently than the lowest timeout value
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout:
%d\nWakeup Idle Timeout: %d\nYou need to call SystemIdleTimerReset at least
every %d sec"),batIdle, acIdle, wakeUpIdle, shortestIdle-1);
}
MessageBox(hWnd,szOutput,_T("Results"),MB_OK);

file://------------------------------------------

// Save the current values.
if ((SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&sm_batIdle,0)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Get"));
}
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&sm_acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0,&sm_wakeUpIdle,0);

tStr.Format(_T("Bat = %d Ac = %d Wake = %d"), sm_batIdle, sm_acIdle,
sm_wakeUpIdle);
AfxMessageBox(tStr);

// Turn off the timeouts.
if ((SystemParametersInfo(SPI_SETBATTERYIDLETIMEOUT,
iSecs,0,SPIF_UPDATEINIFILE)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Setup"));
}
SystemParametersInfo(SPI_SETEXTERNALIDLETIMEOUT,iSecs,0,SPIF_UPDATEINIFILE)
;
SystemParametersInfo(SPI_SETWAKEUPIDLETIMEOUT, iSecs,0,SPIF_UPDATEINIFILE);
if ((SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&sm_batIdle,0)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Get"));
}
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&sm_acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0,&sm_wakeUpIdle,0);

tStr.Format(_T("Bat = %d Ac = %d Wake = %d"), sm_batIdle, sm_acIdle,
sm_wakeUpIdle);
AfxMessageBox(tStr);
}

--
Shankar


.



Relevant Pages

  • preventing Auto Power Off
    ... following code on a device that is running PPC 2002, ... DWORD batIdle, acIdle, wakeUpIdle, shortestIdle; ... // if all values are zero, the device will never timeout ... %d\nWakeup Idle Timeout: %d\nThe device will not timeout."),batIdle, acIdle, ...
    (microsoft.public.pocketpc)
  • reventing Automatic Power Off
    ... following code on a device that is running PPC 2002, ... DWORD batIdle, acIdle, wakeUpIdle, shortestIdle; ... // if all values are zero, the device will never timeout ... %d\nWakeup Idle Timeout: %d\nThe device will not timeout."),batIdle, acIdle, ...
    (microsoft.public.windowsce.app.development)
  • How to prevent Auto Power off
    ... following code on a device that is running PPC 2002, ... DWORD batIdle, acIdle, wakeUpIdle, shortestIdle; ... // if all values are zero, the device will never timeout ... %d\nWakeup Idle Timeout: %d\nThe device will not timeout."),batIdle, acIdle, ...
    (microsoft.public.pocketpc.developer)
  • Re: IIS 6 Session Restarts
    ... The idle timeout for the app pool is set to 20 minutes which is what our ... We do have the application being load balanced using the Load Balancing ... > suggest that you set the idle timeout to be> session timeout to prevent ...
    (microsoft.public.inetserver.iis)