Elevate service restart with UAC prompt in UpdateManager#35
Merged
Conversation
The update PowerShell script runs as the current user (non-admin), but Start-Service requires admin privileges. The previous code used -ErrorAction SilentlyContinue which silently swallowed the access-denied error, leaving the service stopped after every update. Fix by launching an elevated PowerShell subprocess with -Verb RunAs to perform the Start-Service, and refresh the service object before verifying status. https://claude.ai/code/session_01QH1N8t4s4SqfVA1ZcaWSpp
- Update script: try Start-Service directly first, fall back to elevated subprocess only if it fails (avoids unnecessary UAC prompt when the current user already has admin rights). - Program.RunAsService: remove duplicate InitializeContainer() and temp-file cleanup that Main() already performed before reaching this method. - LiteTaskService: remove dead private RunAsService() that duplicated Program.RunAsService() and would dispose the service singleton prematurely via a Using block if ever called. https://claude.ai/code/session_01QH1N8t4s4SqfVA1ZcaWSpp
Move the single-instance mutex check before container initialization so a duplicate process exits immediately without spinning up the full DI container (Logger, CustomScheduler timers, XMLManager, etc.). The check now covers both the default GUI path (no args) and the -elevated path, which previously skipped the mutex entirely and could launch a second GUI alongside an existing one. Also removed the redundant InitializeContainer() call in HandleElevatedMode — Main() already initializes it before dispatch. https://claude.ai/code/session_01QH1N8t4s4SqfVA1ZcaWSpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Modified the service restart logic in UpdateManager to properly handle Windows User Account Control (UAC) elevation requirements when restarting the LiteTaskService.
Key Changes
Start-Servicecall toStart-Processwith-Verb RunAsto trigger UAC elevation prompt$service.Refresh()to ensure status is current before waitingImplementation Details
The service restart now executes in an elevated PowerShell process, which is necessary for starting Windows services that require administrative privileges. The
-WindowStyle Hiddenparameter keeps the elevation prompt clean, and-Waitensures the process completes before continuing. The added$service.Refresh()call ensures the service object reflects the current state before theWaitForStatus()check.