32 lines
883 B
Batchfile
32 lines
883 B
Batchfile
@echo off
|
|
setlocal
|
|
|
|
:: 时间: 2023-10-14 17:54:07
|
|
:: 作者: 岳佳君
|
|
:: 版本: v0.0.2
|
|
:: 功能: 调用同名 ps1 脚本,临时授权可执行
|
|
|
|
:: 获取当前批处理脚本的目录和名称
|
|
set "bat_path=%~dp0"
|
|
set "script_name=%~n0"
|
|
|
|
:: 检查同目录下的同名 .ps1 文件是否存在
|
|
if not exist "%bat_path%%script_name%.ps1" (
|
|
echo Error: PowerShell script "%bat_path%%script_name%.ps1" not found!
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
:: 以 UTF-8 编码运行 PowerShell 脚本
|
|
echo Running PowerShell script (UTF-8): "%bat_path%%script_name%.ps1"
|
|
powershell.exe -ExecutionPolicy Bypass -Command "& { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; . \"%bat_path%%script_name%.ps1\"; exit $LASTEXITCODE }"
|
|
|
|
:: 检查执行是否成功
|
|
if errorlevel 1 (
|
|
echo Error: Failed to execute PowerShell script.
|
|
pause
|
|
exit /b %errorlevel%
|
|
)
|
|
|
|
endlocal
|