Skip to content

Elevate service restart with UAC prompt in UpdateManager#35

Merged
svtica merged 3 commits intomainfrom
claude/debug-service-startup-jdGlz
Mar 19, 2026
Merged

Elevate service restart with UAC prompt in UpdateManager#35
svtica merged 3 commits intomainfrom
claude/debug-service-startup-jdGlz

Conversation

@svtica
Copy link
Copy Markdown
Owner

@svtica svtica commented Mar 19, 2026

Summary

Modified the service restart logic in UpdateManager to properly handle Windows User Account Control (UAC) elevation requirements when restarting the LiteTaskService.

Key Changes

  • Changed from direct Start-Service call to Start-Process with -Verb RunAs to trigger UAC elevation prompt
  • Added service refresh via $service.Refresh() to ensure status is current before waiting
  • Updated error handling comment to clarify that UAC denial is now a possible scenario
  • Improved service startup verification by refreshing service state before checking status

Implementation Details

The service restart now executes in an elevated PowerShell process, which is necessary for starting Windows services that require administrative privileges. The -WindowStyle Hidden parameter keeps the elevation prompt clean, and -Wait ensures the process completes before continuing. The added $service.Refresh() call ensures the service object reflects the current state before the WaitForStatus() check.

claude added 3 commits March 19, 2026 17:12
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
@svtica svtica merged commit 8d49460 into main Mar 19, 2026
1 check passed
@svtica svtica deleted the claude/debug-service-startup-jdGlz branch March 19, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants