From e32a3e12dc22d04f577ecae3e88200b51590ef50 Mon Sep 17 00:00:00 2001 From: PrimeBuild-pc Date: Thu, 22 Oct 2026 06:12:09 +0200 Subject: [PATCH] fix: a leftover HKCU Run entry no longer counts as autostart Windows does not start an admin-only exe from Run at logon, so the entry kept autostart off while the setting showed it on and the startup repair skipped creating the scheduled task. --- Services/AutostartService.cs | 5 +++-- .../AutostartServiceTests.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Services/AutostartService.cs b/Services/AutostartService.cs index 0f487aa..55b70b3 100644 --- a/Services/AutostartService.cs +++ b/Services/AutostartService.cs @@ -163,7 +163,8 @@ namespace ThreadPilot.Services var taskRegistered = await this.elevatedTaskService.IsAutostartTaskRegisteredAsync(); var legacyRegistryValue = this.TryReadLegacyRegistryAutostart(); - this.isAutostartEnabled = taskRegistered || !string.IsNullOrWhiteSpace(legacyRegistryValue); + // Only the task starts an admin-only exe at logon; a leftover HKCU\Run entry does not. + this.isAutostartEnabled = taskRegistered; this.autostartPath = taskRegistered ? $"task://{this.elevatedTaskService.AutostartTaskName}" : legacyRegistryValue; @@ -233,7 +234,7 @@ namespace ThreadPilot.Services } } - private string? TryReadLegacyRegistryAutostart() + internal virtual string? TryReadLegacyRegistryAutostart() { try { diff --git a/Tests/ThreadPilot.Core.Tests/AutostartServiceTests.cs b/Tests/ThreadPilot.Core.Tests/AutostartServiceTests.cs index 91307f7..9358eb6 100644 --- a/Tests/ThreadPilot.Core.Tests/AutostartServiceTests.cs +++ b/Tests/ThreadPilot.Core.Tests/AutostartServiceTests.cs @@ -96,6 +96,25 @@ namespace ThreadPilot.Core.Tests elevatedTaskService.Verify(x => x.RemoveAutostartTaskAsync(), Times.Once); } + [Fact] + public async Task LegacyRunEntryAlone_DoesNotCountAsAutostart() + { + // Windows does not start an admin-only exe from HKCU\Run at logon, so a leftover entry from an + // old version must not stop the scheduled task from being created or show autostart as on. + var elevatedTask = new Mock(MockBehavior.Loose); + elevatedTask.Setup(x => x.IsAutostartTaskRegisteredAsync()).ReturnsAsync(false); + var service = new LegacyRunEntryAutostartService(new Mock().Object, elevatedTask.Object); + + Assert.False(await service.CheckAutostartStatusAsync()); + Assert.False(service.IsAutostartEnabled); + } + + private sealed class LegacyRunEntryAutostartService(IElevationService elevation, IElevatedTaskService elevatedTask) + : AutostartService(NullLogger.Instance, elevation, elevatedTask) + { + internal override string? TryReadLegacyRegistryAutostart() => @"""C:\Apps\ThreadPilot\ThreadPilot.exe"" --autostart"; + } + private static AutostartService CreateService( Mock? elevationService = null, Mock? elevatedTaskService = null)