[TIMEDATE] Use w32time compatible registry settings. CORE-13001

This commit is contained in:
Doug Lyons 2018-04-21 08:13:27 +02:00 committed by Thomas Faber
parent d19b792511
commit 33401f3875
No known key found for this signature in database
GPG key ID: 076E7C3D44720826

View file

@ -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: