Relaunch through UAC when (un)installing the service unprivileged

--install-service/--remove-service on Windows no longer fail with
'Access is denied' from a normal shell: the process re-runs itself via
ShellExecuteEx 'runas', waits for the elevated child and mirrors its
exit code. The child gets --elevated-child and pauses for a keypress so
its console output stays readable. Declining the prompt reports
'UAC prompt declined'.
This commit is contained in:
mram
2026-09-21 08:00:24 +02:00
parent 802a64280f
commit fbab0bba33
7 changed files with 157 additions and 16 deletions
+8 -1
View File
@@ -31,5 +31,12 @@ func Run(run func(ctx context.Context) error) error {
// Install is unsupported on non-Windows, non-Linux platforms.
func Install(string, bool) error { return errUnsupported }
// Remove is unsupported on non-Windows platforms.
// Remove is unsupported on non-Windows, non-Linux platforms.
func Remove() error { return errUnsupported }
// Elevated is always true here: there is no UAC concept, and privilege
// errors surface from the failing operation with a "run as root" hint.
func Elevated() bool { return true }
// RelaunchElevated is unsupported on non-Windows, non-Linux platforms.
func RelaunchElevated([]string) (int, error) { return 0, errUnsupported }