sudo is a Unix-like new feature in Windows 24H2 to get admin privileges. For more information go to Sudo for Windows | Microsoft Learn To execute a cmd script as admin, add the following statement at the top of your script : Code: @reg query HKU\S-1-5-19 >nul 2>nul||(sudo "%~f0"&exit) Example : Code: @reg query HKU\S-1-5-19 >nul 2>nul||(sudo "%~f0"&exit) @ECHO off echo Got Admin. Hit any key to execute powershell commands...&pause >nul set c=Set-Location '%~dp0'; set c=%c%$host.ui.rawui.BackgroundColor = ""Blue""; set c=%c%$host.ui.rawui.ForegroundColor = 'White'; set c=%c%Clear-Host; set c=%c%If(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] ""Administrator"")) set c=%c%{""`r`nWe are executing powershell with admin privileges`r`n""} pwsh -c "%c%;dir" echo Hit any key to exit&pause >nul&exit Following is an other way of doing hybrid batch + powershell scripts + elevation: Code: <# : standard way of doing hybrid batch + powershell scripts + elevation @set c=Set-Location '%~dp0';iex((Get-Content('%~nx0') -Raw)) @reg query HKU\S-1-5-19 >nul 2>nul||(@sudo pwsh -c "%c%"&exit) #> # Powershell statements following # $host.ui.rawui.BackgroundColor = "Blue" $host.ui.rawui.ForegroundColor = "White" Clear-Host If(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {"`r`nWe are executing powershell with admin privileges`r`n"} dir #$pwd Write-Host "Hit any key to exit" -NoNewLine [void][Console]::ReadKey("NoEcho,IncludeKeyDown") [Environment]::Exit(1) In a terminal session, if you need admin privilege to execute a statement, for example dism, enter : Code: sudo dism ... or : Code: sudo pwsh/powershell to execute powershell statements. If you want to switch to admin, enter : Code: sudo cmd
Fyi windows 11 sudo.exe works in windows 7 64bits https://winaero.com/sudo-for-windows-11-actually-runs-on-windows-10-and-windows-7/
I have been using gsudo for several years, and I continue to use it preferring it to the Microsoft supplied version. For a comparison of the two, read here: https://gerardog.github.io/gsudo/docs/gsudo-vs-sudo