通过 Windows 终端获取提升的 .Bat 文件
此脚本成功启动通过 Windows 终端提升的 .ps1 文件
$Admin = (fltmc).count -eq 11
$arg = "-d `"$PSScriptRoot`" -p `"Windows PowerShell`"", "cmd /c powershell -ExecutionPolicy Bypass -File `"$PSCommandPath`""
if ( !$Admin ) { Start -Verb RunAs -FilePath "wt.exe" -ArgumentList $arg; taskkill /f /im $PID; exit }
if ( $Admin ) { 'Running with Admin privilages' } else { 'Required Admin privilages' }
Pause
有谁知道如何通过Windows终端以管理员权限运行bat文件?
此代码在 cmd.exe 中自行提升,而不是在 Windows 终端中/通过 Windows 终端提升
@echo off
Net session >nul 2>&1 || (PowerShell start -verb runas '%~0' &exit /b)
Echo Administrative privileges have been got. & pause
我想要在 Windows 终端中打开批处理文件,如下面的屏幕截图: