Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

I had this text run as a bat file on windows 10 and Ive specified the windows size of…

  1. User

    I had this text run as a bat file on windows 10 and Ive specified the windows size of it. now Im in windows 11 and the window size doesnt work. what should I do? "@echo off cd "C:\Users\Erfan" :: Set the Command Prompt window size (columns x lines) mode con: cols=48 lines=4 :: Ping Google's DNS server indefinitely ping 8.8.8.8 -t "

  2. Assistant

    Windows 11 has introduced some changes to the Command Prompt that might affect how certain commands, like mode con, behave. If your batch file worked as expected on Windows 10 but isn't setting the window size correctly on Windows 11, here are several approaches you can take to resolve the issue:

    1. Use the START Command with Window Size Parameters

    The START command can launch a new Command Prompt window with specific window size parameters. Modify your batch file as follows:

    @echo off
    cd "C:\Users\Erfan"
    :: Start a new Command Prompt window with specified size
    start "" /MIN cmd.exe /k "mode con: cols=48 lines=4 && ping 8.8.8.8 -t"
    

    Explanation:

    • start "" /MIN starts a minimized window (you can remove /MIN if you don't want it minimized).
    • cmd.exe /k runs the specified commands and keeps the window open.
    • The mode con command sets the window size, and ping starts the continuous ping.

    2. Use PowerShell to Set the Window Size

    PowerShell offers more flexibility and control over the console window. You can integrate PowerShell commands within your batch file to set the window size:

    @echo off
    cd "C:\Users\Erfan"
    :: Set window size using PowerShell
    powershell -Command "& {
        $size = New-Object System.Management.Automation.Host.Size(48, 4);
        $host.UI.RawUI.BufferSize = $size;
        $host.UI.RawUI.WindowSize = $size;
    }"
    :: Start pinging
    ping 8.8.8.8 -t
    

    Explanation:

    • The PowerShell script sets both the BufferSize and WindowSize to the desired dimensions.
    • After setting the window size, the batch file proceeds to execute the ping command.

    3. Adjust Command Prompt Properties Manually

    If scripting solutions aren't working as expected, you can manually set the window size:

    1. Open Command Prompt:

      • Press Win + R, type cmd, and press Enter.
    2. Access Properties:

      • Right-click the title bar of the Command Prompt window and select Properties.
    3. Set Layout:

      • Navigate to the Layout tab.
      • Under Window Size, set the desired Width (columns) and Height (lines). For your case, set Width to 48 and Height to 4.
    4. Apply to Shortcut:

      • If you frequently use this batch file, consider creating a shortcut for it.
      • Right-click the batch file, select Create shortcut, then right-click the shortcut and go to Properties to set the desired window size under the Layout tab.

    4. Ensure Compatibility Settings

    Sometimes, compatibility settings can interfere with how scripts run:

    1. Right-Click Batch File:

      • Select Properties.
    2. Navigate to Compatibility Tab:

      • Check Run this program in compatibility mode for: and select Windows 10 if available.
    3. Apply Changes:

      • Click Apply and then OK.

    5. Verify Script Execution Order

    Ensure that the mode con command is placed before other commands that might affect the window state. Here's an optimized version of your script:

    @echo off
    :: Set the Command Prompt window size (columns x lines)
    mode con: cols=48 lines=4
    cd "C:\Users\Erfan"
    :: Ping Google's DNS server indefinitely
    ping 8.8.8.8 -t
    

    Explanation:

    • By placing mode con at the very beginning, you ensure the window size is set before executing other commands.

    6. Use Alternative Terminal Applications

    Windows 11 also supports advanced terminal applications like Windows Terminal, which offers more customization options:

    1. Install Windows Terminal from the Microsoft Store if it's not already installed.
    2. Configure Profiles:
      • Open Windows Terminal.
      • Click the drop-down arrow next to the new tab button and select Settings.
      • Create or modify a profile to set specific window sizes and other preferences.
    3. Run Your Batch File:
      • You can launch your batch file within Windows Terminal, benefiting from its enhanced features.

    Summary

    Windows 11's enhancements to the Command Prompt may require slight adjustments to your batch scripts. By leveraging the START command, integrating PowerShell, manually setting properties, or using alternative terminal applications, you can regain control over the window sizing behavior. Choose the method that best fits your workflow and technical comfort level.

    If you continue to experience issues, consider providing more details or error messages, and I can offer further assistance!