From 96aa8f1ced1c276309b8699f5e97222b70717b7a Mon Sep 17 00:00:00 2001 From: Christ Date: Thu, 13 Aug 2026 13:52:15 +0800 Subject: [PATCH] fix: support Windows PowerShell service scripts --- .github/workflows/desktop-cd.yml | 12 ++++++++++-- packaging/windows/service-control.ps1 | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/desktop-cd.yml b/.github/workflows/desktop-cd.yml index 44cf13e..288ad00 100644 --- a/.github/workflows/desktop-cd.yml +++ b/.github/workflows/desktop-cd.yml @@ -200,16 +200,24 @@ jobs: shell: pwsh run: | go test ./cmd/tray + $serviceScript = (Resolve-Path 'packaging/windows/service-control.ps1').Path $tokens = $null $parseErrors = $null [void][System.Management.Automation.Language.Parser]::ParseFile( - (Resolve-Path 'packaging/windows/service-control.ps1'), + $serviceScript, [ref]$tokens, [ref]$parseErrors ) if ($parseErrors.Count -gt 0) { $parseErrors | ForEach-Object { Write-Error $_.Message } - throw 'Windows 服务安装脚本语法检查失败' + throw 'Windows 服务安装脚本在 PowerShell 7 下语法检查失败' + } + + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" ` + -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass ` + -File $serviceScript -Mode stop -ServiceName "YdisksSyntaxCheck-$PID" + if ($LASTEXITCODE -ne 0) { + throw "Windows 服务安装脚本在 Windows PowerShell 5.1 下检查失败,错误码: $LASTEXITCODE" } - name: 编译 Windows 桌面程序 diff --git a/packaging/windows/service-control.ps1 b/packaging/windows/service-control.ps1 index a77ade9..1e2a778 100644 --- a/packaging/windows/service-control.ps1 +++ b/packaging/windows/service-control.ps1 @@ -1,4 +1,4 @@ -param( +param( [Parameter(Mandatory = $true)] [ValidateSet('stop', 'register', 'start', 'install', 'uninstall')] [string]$Mode,