VideoHelp Forum




+ Reply to Thread
Results 1 to 1 of 1
  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  



Similar Threads

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