diff --git a/dll/cpl/timedate/internettime.c b/dll/cpl/timedate/internettime.c index a5f102af35b..81a3ed0791c 100644 --- a/dll/cpl/timedate/internettime.c +++ b/dll/cpl/timedate/internettime.c @@ -157,7 +157,7 @@ GetSyncSetting(HWND hwnd) DWORD dwSize; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Parameters", + L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) @@ -171,7 +171,9 @@ GetSyncSetting(HWND hwnd) &dwSize) == ERROR_SUCCESS) { if (wcscmp(szData, L"NTP") == 0) - SendDlgItemMessageW(hwnd, IDC_AUTOSYNC, BM_SETCHECK, 0, 0); + SendDlgItemMessageW(hwnd, IDC_AUTOSYNC, BM_SETCHECK, BST_CHECKED, 0); + else + SendDlgItemMessageW(hwnd, IDC_AUTOSYNC, BM_SETCHECK, BST_UNCHECKED, 0); } RegCloseKey(hKey); @@ -187,6 +189,40 @@ OnInitDialog(HWND hwnd) CreateNTPServerList(hwnd); } +static VOID +OnAutoSync(BOOL Sync) +{ + HKEY hKey; + LONG lRet; + LPCWSTR szAuto; + + if (Sync) + szAuto = L"NTP"; + else + szAuto = L"NoSync"; + + lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters", + 0, + KEY_SET_VALUE, + &hKey); + if (lRet != ERROR_SUCCESS) + { + DisplayWin32Error(lRet); + return; + } + + lRet = RegSetValueExW(hKey, + L"Type", + 0, + REG_SZ, + (LPBYTE)szAuto, + (wcslen(szAuto) + 1) * sizeof(WCHAR)); + if (lRet != ERROR_SUCCESS) + DisplayWin32Error(lRet); + + RegCloseKey(hKey); +} /* Property page dialog callback */ INT_PTR CALLBACK @@ -249,6 +285,12 @@ InetTimePageProc(HWND hwndDlg, { case PSN_APPLY: SetNTPServer(hwndDlg); + + if (SendDlgItemMessageW(hwndDlg, IDC_AUTOSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED) + OnAutoSync(TRUE); + else + OnAutoSync(FALSE); + return TRUE; default: