-----Original Message-----
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 said:
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
.