Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sample Code For Daylight Savings Adjustment?

72 views
Skip to first unread message

Tim Houle

unread,
Jun 16, 2004, 10:46:56 AM6/16/04
to
I'm looking For Sample Code For Daylight Savings
Adjustment using EWF - Detect, Commit and Reboot. Doug H -
I've looked everywhere for your old post that has sample
code but couldnt find it. Any ideas?

Thanks,
Tim

Doug Hoeffel

unread,
Jun 16, 2004, 1:18:56 PM6/16/04
to
Tim:

I couldn't find it either. Maybe I was dreamin...

Here it is. You will have to ignore some stuff as this won't compile for
you as is:

bool Verify_LocalTime(void)
{
TIME_ZONE_INFORMATION tzi;
DWORD tzstat = 0;
TCHAR message[512];
int status = 0;
HKEY hKey;
DWORD keyType = 0;
DWORD size = sizeof(DWORD);
DWORD tzi_key = 0;
char command_line[120];
BOOL bstatus = 0;
int iShutdownDelay = 30;

// determine the active time zone
tzstat = GetTimeZoneInformation(&tzi);

// open CAE2_TIME_HIVE
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, CAE2_TIME_HIVE_KEY_NAME, NULL,
KEY_READ | KEY_WRITE, &hKey);
if (status != ERROR_SUCCESS)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
goto Done;
}

// query the value at "TZI (...)"
status = RegQueryValueEx(hKey, TZI_KEY, NULL, &keyType, (LPBYTE)&tzi_key,
&size);
if (status != ERROR_SUCCESS)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
goto Done;
}

if (tzi_key == 99)
{
// Initial condition detected:
// set correct value based on active time zone which is assumed to be
correct
status = RegSetValueEx(hKey, TZI_KEY, NULL, REG_DWORD, (LPBYTE)&tzstat,
sizeof(DWORD));
if (status != ERROR_SUCCESS)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
}
else
{
ctx_log(GEN_LOG_INFO, _T("Local time: %s"),

((tzstat==TIME_ZONE_ID_STANDARD)||(tzi_key==TIME_ZONE_ID_UNKNOWN))?_T("Stand
ard"):_T("Daylight"));
}
}
else // 0, 1, or 2
{
// determine if we switched in/out of daylight savings depending
// on the active time zone
switch (tzstat)
{
case TIME_ZONE_ID_STANDARD:
case TIME_ZONE_ID_DAYLIGHT:
// determine if we need to commit a time change
if (tzstat != tzi_key)
{
// a time change has occured... set "TZI (...)" to adjusted value
status = RegSetValueEx(hKey, TZI_KEY, NULL, REG_DWORD, (LPBYTE)&tzstat,
sizeof(DWORD));
if (status != ERROR_SUCCESS)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
goto Done;
}

// log this change
ctx_log(GEN_LOG_INFO, _T("Local time has changed from %s to %s"),

(((tzi_key==TIME_ZONE_ID_STANDARD)||(tzi_key==TIME_ZONE_ID_UNKNOWN))?_T("Sta
ndard"):_T("Daylight")),
(tzstat==TIME_ZONE_ID_STANDARD?_T("Standard"):_T("Daylight")));

// blank the display
kpdDisplayBlank();
kpdClearLEDs();

// perform EWF commit and perform graceful restart
strcpy(command_line, "EWFCMT.BAT");
ctx_log(GEN_LOG_TRACE, _T("ShellProcessA cmd line: %s"),
TSTR(command_line));
bstatus = ShellProcessA(command_line);
if (bstatus)
{
// update line 1 with time change message
status = kpdTextlineUpdate(KPD_LINE1, (char *)time_change_text);
if (status != KPD_SUCCESS)
ctx_log(GEN_LOG_ERROR, _T("kpdTextlineUpdate error - status = %d"),
status);
// update line 2 with restart system message
status = kpdTextlineUpdate(KPD_LINE2, (char *)restart_system);
if (status != KPD_SUCCESS)
ctx_log(GEN_LOG_ERROR, _T("kpdTextlineUpdate error - status = %d"),
status);

// get the Shutdown Delay from the registry
CConfigData::Instance()->Get_Shutdown_Delay(iShutdownDelay);

// send Shutdown command to Remote firmware
if (RemoteOutThread::Instance()->postShutdownDisplay(iShutdownDelay,
KPD_LINE1, (char *)restart_system) != REMOUT_SUCCESS)
ctx_log(GEN_LOG_ERROR, _T("Unable to post Shutdown message to
remote."));

ctx_log(GEN_LOG_INFO, _T("Graceful RESTART has been requested!"));
// delay before the restart
Sleep(2000);
// perform graceful shutdown and restart
Shutdown_and_Restart();
}
else // shell process error
{
ctx_log(GEN_LOG_ERROR, _T("ShellProcessA error: %s"),
TSTR(command_line));
}
}
else
{
ctx_log(GEN_LOG_INFO, _T("Local time: %s"),
(tzstat==TIME_ZONE_ID_STANDARD?_T("Standard"):_T("Daylight")));
}
break;

case TIME_ZONE_ID_UNKNOWN:
if (tzstat != tzi_key)
{
// set "TZI (...)" to correct value
status = RegSetValueEx(hKey, TZI_KEY, NULL, REG_DWORD, (LPBYTE)&tzstat,
sizeof(DWORD));
if (status != ERROR_SUCCESS)
{
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
}
}
// daylight saving time is not used in the current time zone
ctx_log(GEN_LOG_INFO, _T("Daylight saving time is not used in the
current time zone."));
break;

default:
// error
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&message[0],
sizeof(message), NULL);
ctx_log(GEN_LOG_ERROR, _T("%s"), message);
break;
}
}

Done:
if (hKey)
RegCloseKey(hKey);

return true;
}

"Tim Houle" <tho...@as-e.com> wrote in message
news:1cfdf01c453b0$c579cd60$a601...@phx.gbl...

Tim Houle

unread,
Jun 16, 2004, 3:22:48 PM6/16/04
to
Thanks alot Doug. Much appreciated.

Tim

>.
>

Tim Houle

unread,
Jun 16, 2004, 4:55:50 PM6/16/04
to
Doug,

What are the keys: CAE2_TIME_HIVE_KEY_NAME and TZI_KEY?

Thanks,
Tim

>.
>

Doug Hoeffel

unread,
Jun 16, 2004, 5:40:17 PM6/16/04
to
Tim:

const TCHAR* const CAE2_TIME_HIVE_KEY_NAME = _T("CAE2_TIME_HIVE");
const TCHAR* const TZI_KEY = _T("TZI (0=none,1=Std,2=Daylight)");

CAE2_TIME_HIVE is the name of a registry hive that I use to store the TZI
key value. This registry hive is stored on a partition not protected by
EWF. In my master ghost image, TZI is preset to 99 which is the
uninitialized state. When my product is first built, TZI becomes 0, 1, or 2
depending on the current date and time zone.

HTH
... Doug

"Tim Houle" <anon...@discussions.microsoft.com> wrote in message
news:1da2901c453e4$4e0efaf0$a001...@phx.gbl...

Tim Houle

unread,
Jun 16, 2004, 5:57:32 PM6/16/04
to
Cool. So Doug, I have an .ini file that stores persistent
information on a non-protected partition. I could store
CAE2_TIME_HIVE and TZI_KEY in this file and I would not
need to commit anything or reboot. Am I on the right
page?

Thanks again,
Tim


>-----Original Message-----
>Tim:
>
>const TCHAR* const CAE2_TIME_HIVE_KEY_NAME = _T
("CAE2_TIME_HIVE");
>const TCHAR* const TZI_KEY = _T("TZI
(0=none,1=Std,2=Daylight)");
>
>CAE2_TIME_HIVE is the name of a registry hive that I use
to store the TZI
>key value. This registry hive is stored on a partition
not protected by
>EWF. In my master ghost image, TZI is preset to 99
which is the
>uninitialized state. When my product is first built,
TZI becomes 0, 1, or 2
>depending on the current date and time zone.
>
>HTH

>.... Doug

>.
>

Tim Houle

unread,
Jun 16, 2004, 5:59:32 PM6/16/04
to
Doug, one more thing. You say you store it in a non-
protected hive in the registry. Can we separate registry
hives to another non-protected partition other than where
the OS exists?

>-----Original Message-----
>Tim:
>
>const TCHAR* const CAE2_TIME_HIVE_KEY_NAME = _T
("CAE2_TIME_HIVE");
>const TCHAR* const TZI_KEY = _T("TZI
(0=none,1=Std,2=Daylight)");
>
>CAE2_TIME_HIVE is the name of a registry hive that I use
to store the TZI
>key value. This registry hive is stored on a partition
not protected by
>EWF. In my master ghost image, TZI is preset to 99
which is the
>uninitialized state. When my product is first built,
TZI becomes 0, 1, or 2
>depending on the current date and time zone.
>
>HTH
>.... Doug
>.
>

Doug Hoeffel

unread,
Jun 16, 2004, 6:45:14 PM6/16/04
to
Tim:

Sure, you could use an ini file or create your own registry hive. To create
your own registry hive, which is not part of the default windows registry,
you can create a registry key(s) then export as a registry hive (I think...
its been awhile since I've done this). This is now your registry hive that
you can load, read, close via the Windows API functions RegLoadKey(),
RegOpenKeyEx(), RegCloseKey(). To manually load a registry hive, play with
"Load Hive" in regedit.

With EWF you will still need to commit and reboot atleast if your boot
partition is protected by EWF. The current date/time/time zone is stored in
the registry on the boot partition. My application simply uses the return
value of the GetTimeZoneInformation() API to detect that the current time
zone has changed. I let Windows do this since Windows already knows how to
do it. I just detect this change by comparing what GetTimeZoneInformation()
API returns with what is stored in my registry hive. WHen they are
different, the system just went into or out of daylight saving so I shell a
bat file to commit and reboot. Use the EWF dll API for this. I would of
instead of a bat file but the EWF dll QFE came out too late for me to
deploy.

HTH... Doug

"Tim Houle" <anon...@discussions.microsoft.com> wrote in message

news:1da8e01c453ed$342067b0$a001...@phx.gbl...

Slobodan Brcin (eMVP)

unread,
Jun 16, 2004, 6:58:29 PM6/16/04
to
Ti Tim,

There are powerful functions documented and undocumented functions for manipulating registry (mostly from drivers). So using driver
you could accomplish this, without driver there is only small possibility if you examine native API functions that there might be
functions that would allow you to do that.

Best regards,
Slobodan

"Tim Houle" <anon...@discussions.microsoft.com> wrote in message news:1da8e01c453ed$342067b0$a001...@phx.gbl...

Tim Houle

unread,
Jun 16, 2004, 10:26:45 PM6/16/04
to
Thanks Doug. I understand. I didnt know Win32 registry
I/O calls could perform on files.

Regards,
Tim

>.
>

Tim Houle

unread,
Jun 16, 2004, 10:28:06 PM6/16/04
to
Slobodan,

Thanks for the input.

Regards,
Tim

>.
>

0 new messages