Service: one-click Update-service-to-this-version (no uninstall/reinstall)

Because the service now runs from its own admin-only copy, getting a new build into it
meant uninstall+reinstall (two UAC prompts). Add a DoUpdate path + Service-menu item
that does it in one: stop -> overwrite the ProgramData bin copy from the running app ->
start. Wired as the --update-service verb (elevated), recognised by the service-verb
gate. Enabled only when the service is installed; falls back to a plain install if not.

Note: the service bin folder stays admin-only writable on purpose (a user-writable
SYSTEM binary would be a privilege-escalation hole), so the copy is done elevated via
the one UAC prompt rather than in-process.

Gate: 40/40.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ednunp
2026-07-17 14:55:14 +01:00
co-authored by Claude Opus 4.8
parent b8d0fa5a65
commit fa554cbe35
5 changed files with 34 additions and 5 deletions
+4 -1
View File
@@ -2228,6 +2228,8 @@ public sealed class MainForm : Form
install.Click += (_, _) => ServiceAction(ServiceControl.InstallVerb, "install", confirm: true);
var uninstall = new ToolStripMenuItem("&Uninstall service") { AccessibleName = "Uninstall service" };
uninstall.Click += (_, _) => ServiceAction(ServiceControl.UninstallVerb, "uninstall", confirm: true);
var update = new ToolStripMenuItem("Up&date service to this version") { AccessibleName = "Update service to this version — copies the currently-running RemSound build into the service" };
update.Click += (_, _) => ServiceAction(ServiceControl.UpdateVerb, "update", confirm: false);
var start = new ToolStripMenuItem("S&tart service") { AccessibleName = "Start service" };
start.Click += (_, _) => ServiceAction(ServiceControl.StartVerb, "start", confirm: false);
var stop = new ToolStripMenuItem("Sto&p service") { AccessibleName = "Stop service" };
@@ -2241,7 +2243,7 @@ public sealed class MainForm : Form
{
status, new ToolStripSeparator(),
configure, new ToolStripSeparator(),
install, uninstall, start, stop, new ToolStripSeparator(),
install, uninstall, update, start, stop, new ToolStripSeparator(),
activityLog, updateLog,
});
serviceMenu.DropDownOpening += (_, _) =>
@@ -2261,6 +2263,7 @@ public sealed class MainForm : Form
var installed = state != ServiceState.NotInstalled;
install.Enabled = !installed;
uninstall.Enabled = installed;
update.Enabled = installed; // refresh the service's copy with the running build (stop→copy→start)
start.Enabled = installed && state is ServiceState.Stopped;
stop.Enabled = installed && state is ServiceState.Running;
}