Test if batch file is being run under Powershell or Command prompt or Terminal window.
I occasionally make up batch files with a simple menu.
The menus are set to display correctly when the windows "Default profile" is set to Command Prompt, not Powershell and also not run in a "Terminal" window.
Also the Default terminal application" needs to be set to "Windows Console Host".
The simple "Menu" doesn't display correctly if not run under settings as set out above.
So I want to cancel running the batch files if they are running under "Terminal" Window or "Powershell".
Also cancel if the Default terminal application" is not set to "Windows Console Host".
I need to know at the start of batch file if it's set to run as "Terminal" settings below.
Of course I can set out the following instructions in a readme.txt but it's better to be able to test and cancel batch file if it's not running as required below.
Instructions:
#1. Set "Default profile" to Command Prompt. Not Powershell. ... Press Ctrl + Shift + 2 while the Terminal window is in focus.
#2. Set "Default terminal application" to Windows Console Host. Not "Windows Terminal" and not "Let Windows decide".
#3. Select "Save".
The issue is the test batch always returns CMD even if I temporarily use “Terminal” to change to Powershell, it never returns a result of Powershell.
Code piece from internet used to test. A few more in zip plus description.
https://medium.com/@ranemirusG/tell-whether-it-is-cmd-or-powershell-cb157d0d3633
"This little ‘polyglot’ snippet tells us which CLI are we using. It may be useful in situations where we gain access to a Windows system and know nothing about it."
(dir 2>&1 *`|echo CMD Test #1);&<# rem #>echo PowerShell
Not sure where best to post this query, hope here is ok. Thanks.
+ Reply to Thread
Results 1 to 1 of 1
-
Last edited by JN-; 4th May 2026 at 08:54.
Similar Threads
-
Using Powershell how to test if batch file var is greater than a set value
By JN- in forum Newbie / General discussionsReplies: 10Last Post: 16th Mar 2026, 14:59 -
Get all available graphic cards & put into batch variable using Powershell
By JN- in forum Newbie / General discussionsReplies: 11Last Post: 6th Oct 2025, 14:26 -
Unable to Load DLL File into Command Prompt
By jealousy91 in forum Software PlayingReplies: 1Last Post: 3rd Nov 2021, 13:14 -
Avfs.dll Not Installing When Running on Command Prompt
By jealousy91 in forum Video ConversionReplies: 3Last Post: 26th Oct 2021, 05:58 -
How to get started with youtube-dl from the command prompt
By Baldrick in forum User guidesReplies: 25Last Post: 3rd Jun 2021, 21:13



Quote