How to always open Windows Terminal, not Command Prompt?


profitablePotat

New member
Local time
1:46 AM
Posts
10
Location
Suncheon, South Korea
OS
Windows 11
I made a batch file to set up my computers, and using BatchGotAdmin, I also made it run automatically in administrator mode.

but this is issue or my hope, Windows automatically run Terminal and then Command Prompt in administrator mode.

1688008672162.png this is it.

is there a method to allow Windows Terminal to continue running programs or batch file(code) with administrator privileges?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
Hello, and welcome. :alien:

You could use an option in the tutorial below to change the default terminal application to be Windows Terminal instead of Windows Console Host for this.

 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 2in1 14-eu0098nr (2024)
    CPU
    Intel Core Ultra 7 155H 4.8 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Graphics card(s)
    Integrated Intel Arc
    Sound Card
    Poly Studio
    Monitor(s) Displays
    14" 2.8K OLED multitouch
    Screen Resolution
    2880 x 1800
    Hard Drives
    2 TB PCIe NVMe M.2 SSD
    Internet Speed
    Intel Wi-Fi 7 BE200 (2x2) and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender and Malwarebytes Premium
Hello, and welcome. :alien:

You could use an option in the tutorial below to change the default terminal application to be Windows Terminal instead of Windows Console Host for this.

I mean, I changed all of these but not working.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
As a test, use the command below to start the command line with to have it open using Windows Terminal.

wt cmd /k
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 2in1 14-eu0098nr (2024)
    CPU
    Intel Core Ultra 7 155H 4.8 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Graphics card(s)
    Integrated Intel Arc
    Sound Card
    Poly Studio
    Monitor(s) Displays
    14" 2.8K OLED multitouch
    Screen Resolution
    2880 x 1800
    Hard Drives
    2 TB PCIe NVMe M.2 SSD
    Internet Speed
    Intel Wi-Fi 7 BE200 (2x2) and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender and Malwarebytes Premium
As a test, use the command below to start the command line with to have it open using Windows Terminal.

wt cmd /k
1688009936679.png
I implemented that in batch file but it seems like broken.

What I'm now trying is batch codes are continuosly working in the Windows terminal. Double-clicking or selecting "Open in Administrator Mode" in context menu opens Command Prompt with administrator mode.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
Go ahead and post the code here to see where the error is.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 2in1 14-eu0098nr (2024)
    CPU
    Intel Core Ultra 7 155H 4.8 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Graphics card(s)
    Integrated Intel Arc
    Sound Card
    Poly Studio
    Monitor(s) Displays
    14" 2.8K OLED multitouch
    Screen Resolution
    2880 x 1800
    Hard Drives
    2 TB PCIe NVMe M.2 SSD
    Internet Speed
    Intel Wi-Fi 7 BE200 (2x2) and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender and Malwarebytes Premium
Go ahead and post the code here to see where the error is.
Gotcha. Here's the whole codes

+ You should ignore some PowerShell errors. It is some kind of NotImplementedError 😐

Batch:
@echo off
wt cmd /k
Title [230622] Windows 11 Automatic Optimization and Settings
:: echo highlighting
for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
:: BatchGotAdmin
::-------------------------------------
::  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:: --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"="
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
::--------------------------------------
echo BatchGotAdmin just got administrative privileges and good to go.
pause
cls
:: ESCAPING, USE GUIDE FOR STYLEs OR COLORS
:: %ESC%[ %ESC%[0m
echo %ESC%[7mTHIS BATCH SCRIPT IS FOR WINDOWS 11 EXCLUSIVELY. USE AT YOUR OWN RISK.%ESC%[0m
echo %ESC%[7mOPEN IN ADMINISTRATOR MODE%ESC%[0m
echo %ESC%[7mNOW WORKING...%ESC%[0m
echo:
echo:
pause
:: SHORTCUT ICONS
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "29" /t REG_EXPAND_SZ /d "%systemroot%\Blank.ico" /f
taskkill /F /IM explorer.exe
start "" explorer.exe
echo %ESC%[7m+ SHORTCUT ICON DISABLED%ESC%[0m
echo:
:: POWER OPTIONS
Powershell.exe ExecutionPolicy Bypass
echo %ESC%[7m! MAY %ESC%[3mExecutionPolicy%ESC%[0m%ESC%[7mHAS BYPASSED EARLIER. CONTINUING...%ESC%[0m
Powershell.exe Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Power' -Name 'CSEnabled' -Value 0 -Force
echo %ESC%[7m + RAN PowerShell FOR UNHIDING POWER OPTIONS%ESC%[0m
::WinRAR KEY INSTALL (AFTER WinRAR HAS INSTALLED.)
set "directoryPath=C:\Program Files\WinRAR"
set "fileName=rarreg.key"
if exist "%directoryPath%\" (
        (
        echo >> [deleted. it is WinRAR eval key]
    ) > "%directoryPath%\%fileName%"
) else (
    echo The specified directory does not exist or is unavailable.
    echo Skipping file copying codes.
)
echo %ESC%[7m+ WinRAR KEY INSTALLED! %ESC%[0m
echo.
:: [some registry keys here. no issues]
echo %ESC%[7m+ POWER RELATED OPTIMIZATION  %ESC%[0m
echo.
Reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows\DataCollection" /v "AllowTelemetry" /t REG_DWORD /d "0" /f
echo %ESC%[7m+ MICROSOFT TELEMETRY DISABLED %ESC%[0m
echo.
Reg.exe delete "HKCU\Software\Microsoft\Internet Explorer\SearchScopes\{5CE25775-92B7-477d-9603-852F0B34D8B0}" /f
Reg.exe delete "HKCU\Software\Microsoft\Internet Explorer\SearchScopes\{B2D17A31-2642-4D03-9D1F-ABD3BE1DCC4E}" /f
Reg.exe delete "HKCU\Software\Microsoft\Internet Explorer\SearchScopes\{0633EE93-D776-472f-A0FF-E1416B8B2E3A}" /f
echo %ESC%[7m+ DETECTED AND REMOVED CHINESE SITES ON IE %ESC%[0m
echo.
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications" /v "GlobalUserDisabled" /t REG_DWORD /d "1" /f
echo %ESC%[7m+ BACKGROUND APPS DISABLED %ESC%[0m
echo.
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\PrecisionTouchPad" /v "AAPThreshold" /t REG_DWORD /d "0" /f
echo %ESC%[7m+ DISABLED KEYBOARD DELAY AFTER TRACKPAD WORKED%ESC%[0m
echo.
reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve
echo %ESC%[7m+ OLD CONTEXT MENU ENABLED %ESC%[0m
echo.


pause
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
It's easier to do with a one liner, but this will be a bit more work.

We'll need someone with more code experience to help.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    8TB WD MyCloudEX2Ultra NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Logitech wireless K800
    Mouse
    Logitech MX Master 3
    Internet Speed
    1 Gbps Download and 35 Mbps Upload
    Browser
    Google Chrome
    Antivirus
    Microsoft Defender and Malwarebytes Premium
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    APC SMART-UPS RT 1000 XL - SURT1000XLI,
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Spectre x360 2in1 14-eu0098nr (2024)
    CPU
    Intel Core Ultra 7 155H 4.8 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Graphics card(s)
    Integrated Intel Arc
    Sound Card
    Poly Studio
    Monitor(s) Displays
    14" 2.8K OLED multitouch
    Screen Resolution
    2880 x 1800
    Hard Drives
    2 TB PCIe NVMe M.2 SSD
    Internet Speed
    Intel Wi-Fi 7 BE200 (2x2) and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Windows Defender and Malwarebytes Premium
Wouldn't it be tidier, and easier in the long run, to write all of it in PowerShell?
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
This command doesn't bypass UAC (which is another issue), but it opens Terminal as Admin, runs a batch script before returning to local CMD shell. I think that's what you wanted...
Code:
powershell Start-Process -Verb RunAs wt.exe -ArgumentList '-d %~dp0 cmd.exe /k hello.bat'

Capture.PNG
 

My Computer

System One

  • OS
    Windows 7
This command doesn't bypass UAC (which is another issue), but it opens Terminal as Admin, runs a batch script before returning to local CMD shell. I think that's what you wanted...
Code:
powershell Start-Process -Verb RunAs wt.exe -ArgumentList '-d %~dp0 cmd.exe /k hello.bat'

View attachment 63575
UAC is not issue for me. Thanks for the code. But...

It is LOOPING AS HELL and kinda funny so im trying to find a solution!

1688016219145.png
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
What exactly did you change in your environment? I'm running an untouched Windows, did you follow Brink's tutorial?
 

My Computer

System One

  • OS
    Windows 7
What exactly did you change in your environment? I'm running an untouched Windows, did you follow Brink's tutorial?
I changed them long time ago, default Windows command prompt.

and excluding appearances, I didn't changed or modified anything.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
If you're running the script you wrote, don't because the beginning has all sorts of UAC elevation logic that isn't needed. Terminal will be running as Admin so none of that code is required, and it should be normal batch commands.
 

My Computer

System One

  • OS
    Windows 7
That'll be cool and I thought that too a lot. but sadly, I don't know much about PowerShell syntaxes.
Nothing like having a real project as a motivation to learn and with AI, like ChatGPT, available, the learning curve is much gentler these days.

From what I see of your code, I think you could get up to speed with PowerShell very quickly.
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
If you're running the script you wrote, don't because the beginning has all sorts of UAC elevation logic that isn't needed. Terminal will be running as Admin so none of that code is required, and it should be normal batch commands.
Got it. but when I manipulating registries, it always says "Access denied" so I just put them.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
Nothing like having a real project as a motivation to learn and with AI, like ChatGPT, available, the learning curve is much gentler these days.

From what I see of your code, I think you could get up to speed with PowerShell very quickly.
That's right. I will try to convert to PowerShell now. thanks
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo 14ARE05(82A2)
    CPU
    AMD Ryzen 4500U
That's right. I will try to convert to PowerShell now. thanks

Just to get you off to a good start, here's a tidbit that will save you from going crazy...

PowerShell variables have scope. Variables created in the main code can be read within any function, but require the $Script or $Global prefix to change them within a function. If you don't use one of those prefixes, the variable assignment within the function will create a new local variable that is completely separate from your global variable. Of course, your computer science teacher will tell you not to use global variables at all and, instead, always pass variables into a function and return results. But sometimes its just easier to work with a global variable and you then you need to understand the scope.

Example 1:

Powershell:
function bar {
  Write-Host $foo
  $foo = "b"
}
$foo = "a"
bar
Write-Host $foo
Output:
a
a

In this case, the $foo = "b" assignment, in the bar function, creates a new local variable, instead of changing the main code's $foo variable.

Example 2:

Powershell:
function bar {
  Write-Host $foo
  $Script:foo = "b"
}
$foo = "a"
bar
Write-Host $foo
Output:
a
b

In this case, the $Script:foo = "b" assignment, in the bar function, changes the main code's $foo variable.

Note: The $Global prefix changes a variable across the entire PowerShell session, whereas the, $Script prefix changes the variable only for the current script. Generally, $Script is all that's needed.
 

My Computer

System One

  • OS
    Windows 10/11
    Computer type
    Laptop
    Manufacturer/Model
    Acer
Back
Top Bottom