[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,15 +20,15 @@ namespace Microsoft.PowerToys.Telemetry
try try
{ {
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0); registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0);
}
catch
{
}
if (registryValue is not null) if (registryValue is not null)
{ {
return (int)registryValue == 1 ? true : false; return (int)registryValue == 1 ? true : false;
} }
}
catch
{
}
return false; return false;
} }

View File

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