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:
@@ -33,6 +33,15 @@ const (
|
||||
// IsService reports whether the process was started by systemd.
|
||||
func IsService() bool { return os.Getenv("INVOCATION_ID") != "" }
|
||||
|
||||
// Elevated is always true on Linux: there is no UAC equivalent; privilege
|
||||
// errors surface from the failing operation with a "run as root" hint.
|
||||
func Elevated() bool { return true }
|
||||
|
||||
// RelaunchElevated is a Windows-only concept (UAC).
|
||||
func RelaunchElevated([]string) (int, error) {
|
||||
return 0, fmt.Errorf("elevated relaunch is only supported on Windows")
|
||||
}
|
||||
|
||||
// Run executes run with SIGINT/SIGTERM cancellation (which is how systemctl
|
||||
// stop signals the process) and tells systemd when the shutdown begins.
|
||||
func Run(run func(ctx context.Context) error) error {
|
||||
|
||||
Reference in New Issue
Block a user