[runner]Fix crashes caused by wrong setting AllowDataDiagnostics registry value (#37015)

* Fix setting registry value

* Prevent future similar crashes
This commit is contained in:
Stefan Markovic 2025-01-22 19:49:31 +01:00 committed by GitHub
parent 422096b907
commit b6b941c55b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View File

@ -20,16 +20,16 @@ namespace Microsoft.PowerToys.Telemetry
try
{
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0);
if (registryValue is not null)
{
return (int)registryValue == 1 ? true : false;
}
}
catch
{
}
if (registryValue is not null)
{
return (int)registryValue == 1 ? true : false;
}
return false;
}

View File

@ -174,9 +174,8 @@ namespace PTSettingsHelper
return;
}
const bool value = enabled;
const size_t buf_size = sizeof(bool);
if (RegSetValueExW(key, DataDiagnosticsRegValueName, 0, REG_QWORD, reinterpret_cast<const BYTE*>(&value), buf_size) != ERROR_SUCCESS)
const DWORD value = enabled ? 1 : 0;
if (RegSetValueExW(key, DataDiagnosticsRegValueName, 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(value)) != ERROR_SUCCESS)
{
RegCloseKey(key);
return;