From 064dbb7561102b310320543eafd44119ffd35ba2 Mon Sep 17 00:00:00 2001 From: Zhengen TANG Date: Fri, 11 Sep 2026 14:00:34 +0800 Subject: [PATCH] =?UTF-8?q?install-nssm-services.ps1:=20=E5=B1=80=E9=83=A8?= =?UTF-8?q?=E9=99=8D=E7=BA=A7=20ErrorActionPreference=20=E4=BB=A5=E8=A7=84?= =?UTF-8?q?=E9=81=BF=E9=A6=96=E6=AC=A1=E5=AE=89=E8=A3=85=20stop/remove=20?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E4=B8=AD=E6=96=AD=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/windows/install-nssm-services.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deploy/windows/install-nssm-services.ps1 b/deploy/windows/install-nssm-services.ps1 index a937181..8773293 100644 --- a/deploy/windows/install-nssm-services.ps1 +++ b/deploy/windows/install-nssm-services.ps1 @@ -32,8 +32,14 @@ function Install-NssmService { [string]$WorkingDirectory ) + # 首次安装时服务尚不存在,stop/remove 必然失败(写 stderr + 非 0 退出码)。 + # $PSNativeCommandUseErrorActionPreference 在部分环境下未必生效,这里显式把 + # $ErrorActionPreference 局部降级为 SilentlyContinue,确保这两步失败不会中断脚本。 + $prevEAP = $ErrorActionPreference + $ErrorActionPreference = "SilentlyContinue" & $Nssm stop $Name 2>$null | Out-Null & $Nssm remove $Name confirm 2>$null | Out-Null + $ErrorActionPreference = $prevEAP & $Nssm install $Name $Application $Arguments & $Nssm set $Name AppDirectory $WorkingDirectory