Skip to content

Commit

Permalink
Log exceptions when failing to write registry keys (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
srwi committed Sep 15, 2024
1 parent 6db022e commit c9303d1
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions EverythingToolbar.Launcher/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static bool IsTaskbarCenterAligned()
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"))
{
var taskbarAlignment = key?.GetValue("TaskbarAl");
Logger.Debug($"taskbarAlignment: {taskbarAlignment}");
var leftAligned = taskbarAlignment != null && (int)taskbarAlignment == 0;
return !leftAligned;
}
Expand All @@ -77,9 +76,16 @@ public static bool GetWindowsSearchEnabledState()

public static void SetWindowsSearchEnabledState(bool enabled)
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Search", true))
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Search", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key?.SetValue("SearchboxTaskbarMode", enabled ? 1 : 0);
try
{
key?.SetValue("SearchboxTaskbarMode", enabled ? 1 : 0);
}
catch (Exception e)
{
Logger.Error(e, "Failed to set taskbar search icon mode.");
}
}
}

Expand All @@ -93,12 +99,19 @@ public static bool GetAutostartState()

public static void SetAutostartState(bool enabled)
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (enabled)
key?.SetValue("EverythingToolbar", "\"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
else
key?.DeleteValue("EverythingToolbar", false);
try
{
if (enabled)
key?.SetValue("EverythingToolbar", "\"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
else
key?.DeleteValue("EverythingToolbar", false);
}
catch (Exception e)
{
Logger.Error(e, "Failed to set autostart state.");
}
}
}

Expand Down

0 comments on commit c9303d1

Please sign in to comment.