VideoHelp Forum




+ Reply to Thread
Results 1 to 3 of 3
  1. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    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.
    Image Attached Files
    Last edited by JN-; 4th May 2026 at 08:54.
    Quote Quote  
  2. Member
    Join Date
    Jun 2022
    Location
    Dublin
    Search Comp PM
    Anyone?
    Quote Quote  
  3. 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),
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!