运行通过 Windows 终端提升的批处理文件

问题描述 投票:0回答:1

通过 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 终端中打开批处理文件,如下面的屏幕截图:

batch-file elevated-privileges windows-terminal
1个回答
0
投票

此代码仅在bat文件不包含空格时有效

@echo off 
fltmc >nul || (powershell start -verb runas wt.exe "%~0"&exit)
Echo Administrative privileges have been got. & pause

© www.soinside.com 2019 - 2024. All rights reserved.