I had this text run as a bat file on windows 10 and Ive specified the windows size of…
- 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 "
- 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
STARTCommand with Window Size ParametersThe
STARTcommand 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 "" /MINstarts a minimized window (you can remove/MINif you don't want it minimized).cmd.exe /kruns the specified commands and keeps the window open.- The
mode concommand sets the window size, andpingstarts 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 -tExplanation:
- The PowerShell script sets both the
BufferSizeandWindowSizeto the desired dimensions. - After setting the window size, the batch file proceeds to execute the
pingcommand.
3. Adjust Command Prompt Properties Manually
If scripting solutions aren't working as expected, you can manually set the window size:
-
Open Command Prompt:
- Press
Win + R, typecmd, and pressEnter.
- Press
-
Access Properties:
- Right-click the title bar of the Command Prompt window and select
Properties.
- Right-click the title bar of the Command Prompt window and select
-
Set Layout:
- Navigate to the
Layouttab. - Under
Window Size, set the desiredWidth(columns) andHeight(lines). For your case, setWidthto48andHeightto4.
- Navigate to the
-
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 toPropertiesto set the desired window size under theLayouttab.
4. Ensure Compatibility Settings
Sometimes, compatibility settings can interfere with how scripts run:
-
Right-Click Batch File:
- Select
Properties.
- Select
-
Navigate to Compatibility Tab:
- Check
Run this program in compatibility mode for:and selectWindows 10if available.
- Check
-
Apply Changes:
- Click
Applyand thenOK.
- Click
5. Verify Script Execution Order
Ensure that the
mode concommand 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 -tExplanation:
- By placing
mode conat 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:
- Install Windows Terminal from the Microsoft Store if it's not already installed.
- 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.
- 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
STARTcommand, 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!