Skip to content

Commit

Permalink
add logging, handle unspecified case differently
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau committed Nov 8, 2024
1 parent 8519825 commit a583bab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion common/Helpers/GPOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// Licensed under the MIT License.

using Microsoft.Win32;
using Serilog;

namespace DevHome.Common.Helpers;

public class GPOHelper
{
private static readonly ILogger _log = Log.ForContext("SourceContext", nameof(GPOHelper));

private enum GpoRuleConfigured
{
WrongValue = -3, // The policy is set to an unrecognized value
Expand All @@ -32,12 +35,14 @@ private static GpoRuleConfigured GetConfiguredValue(string registryValueName)
valueName: registryValueName,
defaultValue: GpoRuleConfigured.NotConfigured);

_log.Error($"Registry value {registryValueName} set to {rawValue}");

// Value will be null if the subkey specified by keyName does not exist.
if (rawValue == null)
{
return GpoRuleConfigured.NotConfigured;
}
else if (rawValue is not int)
else if (rawValue is not int && rawValue is not GpoRuleConfigured)
{
return GpoRuleConfigured.WrongValue;
}
Expand Down Expand Up @@ -68,6 +73,7 @@ private static bool EvaluateConfiguredValue(string registryValueName, GpoRuleCon
var configuredValue = GetConfiguredValue(registryValueName);
if (configuredValue < 0)
{
_log.Error($"Registry value {registryValueName} set to {configuredValue}, using default {defaultValue} instead.");
configuredValue = defaultValue;
}

Expand Down

0 comments on commit a583bab

Please sign in to comment.