From 6748edc6ee28831dbc994c4d2ecdad982fa39f0e Mon Sep 17 00:00:00 2001 From: Marco Maroni <166719395+marcomaroni-github@users.noreply.github.com> Date: Tue, 14 Jul 2026 16:29:40 +0200 Subject: [PATCH] feat: HKCU\Run fallback for start-at-login when unpackaged (classic install) StartupManager now falls back to the Run registry key when the MSIX StartupTask API is unavailable, so the tray toggle works in the classic installer build and stays consistent with the installer-set Run value. Co-Authored-By: Claude Opus 4.8 (1M context) --- StartupManager.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/StartupManager.cpp b/StartupManager.cpp index e5afeeb..f8457f5 100644 --- a/StartupManager.cpp +++ b/StartupManager.cpp @@ -11,6 +11,39 @@ using namespace winrt::Windows::ApplicationModel; namespace { const wchar_t* kTaskId = L"TaskbarCalculatorStartup"; + const wchar_t* kRunKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + const wchar_t* kRunVal = L"TaskbarCalculator"; + + // --- HKCU\...\Run fallback (used when the app has no package identity) --- + bool RunKeyExists() { + HKEY h; + if (RegOpenKeyExW(HKEY_CURRENT_USER, kRunKey, 0, KEY_QUERY_VALUE, &h) != ERROR_SUCCESS) + return false; + LONG r = RegQueryValueExW(h, kRunVal, nullptr, nullptr, nullptr, nullptr); + RegCloseKey(h); + return r == ERROR_SUCCESS; + } + + bool RunKeySet(bool on) { + HKEY h; + if (RegCreateKeyExW(HKEY_CURRENT_USER, kRunKey, 0, nullptr, 0, + KEY_SET_VALUE, nullptr, &h, nullptr) != ERROR_SUCCESS) + return false; + LONG r; + if (on) { + wchar_t path[MAX_PATH]; + GetModuleFileNameW(nullptr, path, MAX_PATH); + wchar_t quoted[MAX_PATH + 2]; + wsprintfW(quoted, L"\"%s\"", path); + r = RegSetValueExW(h, kRunVal, 0, REG_SZ, (const BYTE*)quoted, + (DWORD)((lstrlenW(quoted) + 1) * sizeof(wchar_t))); + } else { + r = RegDeleteValueW(h, kRunVal); + if (r == ERROR_FILE_NOT_FOUND) r = ERROR_SUCCESS; + } + RegCloseKey(h); + return r == ERROR_SUCCESS; + } } namespace Startup { @@ -26,7 +59,8 @@ State Get() { return State::Disabled; } } catch (...) { - return State::Unavailable; // unpackaged / API missing + // Unpackaged (classic install): use the HKCU\Run fallback. + return RunKeyExists() ? State::Enabled : State::Disabled; } } @@ -42,7 +76,7 @@ bool Set(bool on) { return true; } } catch (...) { - return false; + return RunKeySet(on); } } -- 2.51.2