Run Batch-file Elevated through Windows Terminal

117 Views Asked by At

Get Elevated .Bat File through Windows Terminal

This script succesfully start .ps1 file elevated through Windows Terminal

$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

Does anyone know how to run bat file with admin privilege through Windows Terminal?

This code get elevated in cmd.exe it self, not in/ through windows terminal

@echo off 
Net session >nul 2>&1 || (PowerShell start -verb runas '%~0' &exit /b)
Echo Administrative privileges have been got. & pause

cmd elevated

I want the batch file opened in windows terminal like screenshoot below:

wt.exe

1

There are 1 best solutions below

4
ItsSuperPlayz On

Terminal is a "virtual machine" to run CMD, in reality, you're actually using CMD and its processes (see image below) with the key difference being the ability to handle some special characters (for example, emojis).

So there is no need to care about whether your script runs in Terminal or CMD, it's all the same (except if you like how Terminal looks, or, if you use special characters)

Terminal using CMD processes