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.
This commit is contained in:
PrimeBuild-pc
2026-10-22 06:12:09 +02:00
committed by Prime Build
parent 9ff7085af8
commit e32a3e12dc
2 changed files with 22 additions and 2 deletions
+3 -2
View File
@@ -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
{
@@ -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<IElevatedTaskService>(MockBehavior.Loose);
elevatedTask.Setup(x => x.IsAutostartTaskRegisteredAsync()).ReturnsAsync(false);
var service = new LegacyRunEntryAutostartService(new Mock<IElevationService>().Object, elevatedTask.Object);
Assert.False(await service.CheckAutostartStatusAsync());
Assert.False(service.IsAutostartEnabled);
}
private sealed class LegacyRunEntryAutostartService(IElevationService elevation, IElevatedTaskService elevatedTask)
: AutostartService(NullLogger<AutostartService>.Instance, elevation, elevatedTask)
{
internal override string? TryReadLegacyRegistryAutostart() => @"""C:\Apps\ThreadPilot\ThreadPilot.exe"" --autostart";
}
private static AutostartService CreateService(
Mock<IElevationService>? elevationService = null,
Mock<IElevatedTaskService>? elevatedTaskService = null)