diff --git a/Directory.Build.props b/Directory.Build.props index 65b6f43..434a152 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 0.1.0 + 0.1.1 Justin Paul Justin Paul Webhook Server diff --git a/installer/webhook-server.iss b/installer/webhook-server.iss index 36c7314..b97f5ef 100644 --- a/installer/webhook-server.iss +++ b/installer/webhook-server.iss @@ -77,3 +77,41 @@ Filename: "powershell.exe"; \ Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\scripts\uninstall-service.ps1"""; \ Flags: runhidden; \ RunOnceId: "RemoveWebhookService" + +[Code] +function ServiceExists(): Boolean; +var + ResultCode: Integer; +begin + // sc.exe query returns 0 when the service exists, 1060 when it does not. + Exec(ExpandConstant('{sys}\sc.exe'), 'query WebhookServer', '', SW_HIDE, + ewWaitUntilTerminated, ResultCode); + Result := (ResultCode = 0); +end; + +function PrepareToInstall(var NeedsRestart: Boolean): String; +var + ResultCode: Integer; +begin + Result := ''; + + // 1. If the service exists, stop it so its binaries are unlocked before file + // copy. net stop is synchronous (blocks until the service is actually + // stopped), unlike sc stop which is fire-and-forget. Non-zero exit - + // already stopped, missing, dependency error - we ignore; the file copy + // will fail loudly if the binaries are still locked. + if ServiceExists() then + begin + WizardForm.PreparingLabel.Caption := 'Stopping the WebhookServer service...'; + Exec(ExpandConstant('{sys}\net.exe'), 'stop WebhookServer', '', SW_HIDE, + ewWaitUntilTerminated, ResultCode); + end; + + // 2. Kill any running GUI / tray instances so their binaries are unlocked too. + // /f forces termination, /im matches by image name, "*" wildcard would be + // risky so we name them explicitly. + Exec(ExpandConstant('{sys}\taskkill.exe'), '/f /im WebhookServer.Gui.exe', + '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + Exec(ExpandConstant('{sys}\taskkill.exe'), '/f /im WebhookServer.Service.exe', + '', SW_HIDE, ewWaitUntilTerminated, ResultCode); +end; diff --git a/src/WebhookServer.Gui/MainWindow.xaml b/src/WebhookServer.Gui/MainWindow.xaml index a2ff565..64f037c 100644 --- a/src/WebhookServer.Gui/MainWindow.xaml +++ b/src/WebhookServer.Gui/MainWindow.xaml @@ -29,8 +29,9 @@ -