NavisworksTransport/deploy-plugin.bat
tian ead8a35372 refactor: 部署脚本先普通权限部署,失败才提权,避免无谓UAC
deploy-plugin.bat 原为:非管理员直接 Start-Process RunAs 提权弹UAC。
但文件可写且 Roamer 可被当前用户关闭时根本不需要管理员。

重构:抽取部署主体到 deploy-body.ps1(关Roamer+等解锁+复制+校验+设写权限)。
deploy-plugin.bat 先以当前用户运行 deploy-body.ps1,成功则免UAC;
失败(如文件被管理员所有)才提权重试。
bat 用纯ASCII注释避免中文编码乱码问题。
2026-07-31 16:52:48 +08:00

30 lines
1.0 KiB
Batchfile

@echo off
setlocal
REM ============================================================
REM Deploy script. Tries to deploy with current user privileges first
REM (no UAC). Only elevates and retries if normal deployment fails
REM (e.g. target files are owned by Administrator).
REM Actual deployment logic is in deploy-body.ps1.
REM ============================================================
set "SCRIPT_DIR=%~dp0"
REM First attempt: deploy with current user permissions
pwsh -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%deploy-body.ps1"
if %ERRORLEVEL% EQU 0 (
echo Deployment succeeded without elevation.
exit /b 0
)
REM Normal deploy failed. Elevate and retry.
echo Deployment failed with current user permissions. Retrying with administrator rights...
PowerShell -Command "Start-Process -FilePath 'pwsh.exe' -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-File','\"%SCRIPT_DIR%deploy-body.ps1\"' -Verb RunAs -Wait"
if errorlevel 1 (
echo Deployment failed.
exit /b 1
)
echo Plugin deployed successfully.
exit /b 0