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