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 3 of 3
-
Last edited by JN-; 4th May 2026 at 08:54.
-
Using batch scripts, to avoid to all this batch script hacking madness and insanity, what I ended up using, sort of as a "menu", was actually launching notepad files, that could be edited by user (changing options, avisynth lines, etc.) and after saving file and canceling it, batch script would just continue parsing that notepad file and then continuing further in a merry way ....
So been there, done that (doing simple menus), but switched to python and Im just amazed since, it is a ride. You'd get there, and you will enjoy it, guaranteed, in months, doing guis, menus etc., recommend picking up pyqt6 for python (QT 6 version for menu) or tkinter (easier, limitations, but I use it, no problems),
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