diff --git a/base/services/w32time/w32time.c b/base/services/w32time/w32time.c index 69c6bd15abe..a0dc7657037 100644 --- a/base/services/w32time/w32time.c +++ b/base/services/w32time/w32time.c @@ -241,6 +241,10 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv) { int result; DWORD dwInterval; + HKEY hKey; + WCHAR szData[8]; + DWORD dwSize; + BOOL bAutoSync = FALSE; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); @@ -282,26 +286,53 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv) /* The worker loop of a service */ for (;;) { - result = SetTime(); + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters", + 0, + KEY_QUERY_VALUE, + &hKey) == ERROR_SUCCESS) + { + dwSize = 8 * sizeof(WCHAR); + if (RegQueryValueExW(hKey, + L"Type", + NULL, + NULL, + (LPBYTE)szData, + &dwSize) == ERROR_SUCCESS) + { + bAutoSync = (wcscmp(szData, L"NTP") == 0); + } + + RegCloseKey(hKey); + } + + if (bAutoSync) + { + result = SetTime(); - if (result) - DPRINT("W32Time Service failed to set clock.\n"); - else - DPRINT("W32Time Service successfully set clock.\n"); + if (result) + DPRINT("W32Time Service failed to set clock.\n"); + else + DPRINT("W32Time Service successfully set clock.\n"); - if (result) + if (result) + { + /* In general we do not want to stop this service for a single + * Internet read failure but there may be other reasons for which + * we really might want to stop it. + * Therefore this code is left here to make it easy to stop this + * service when the correct conditions can be determined, but it + * is left commented out. + ServiceStatus.dwCurrentState = SERVICE_STOPPED; + ServiceStatus.dwWin32ExitCode = result; + SetServiceStatus(hStatus, &ServiceStatus); + return; + */ + } + } + else { - /* In general we do not want to stop this service for a single - * Internet read failure but there may be other reasons for which - * we really might want to stop it. - * Therefore this code is left here to make it easy to stop this - * service when the correct conditions can be determined, but it - * is left commented out. - ServiceStatus.dwCurrentState = SERVICE_STOPPED; - ServiceStatus.dwWin32ExitCode = result; - SetServiceStatus(hStatus, &ServiceStatus); - return; - */ + DPRINT1("W32Time Service disabled.\n"); } if (WaitForSingleObject(hStopEvent, dwInterval * 1000) == WAIT_OBJECT_0)