How to change Screen buffer size in Windows Command Prompt from batch script

后端 未结 14 1506
清歌不尽
清歌不尽 2020-12-02 09:59

I know you can do right click properties ->layout and there change it manually.

But how would you go about changing it from a Windows batch script?

I know yo

14条回答
  •  [愿得一人]
    2020-12-02 10:24

    Here's what I did in case someone finds it useful (I used a lot of things according to the rest of the answers in this thread):

    First I adjusted the layout settings as needed. This changes the window size immediately so it was easier to set the exact size that I wanted. By the way I didn't know that I can also have visible width smaller than width buffer. This was nice since I usually hate a long line to be wrapped. enter image description here

    Then after clicking ok, I opened regedit.exe and went to "HKEY_CURRENT_USER\Console". There is a new child entry there "%SystemRoot%_system32_cmd.exe". I right clicked on that and selected Export: enter image description here

    I saved this as "cmd_settings.reg". Then I created a batch script that imports those settings, invokes my original batch script (name batch_script.bat) and then deletes what I imported in order for the command line window to return to default settings:

    regedit /s cmd_settings.reg
    start /wait batch_script.bat
    reg delete "HKEY_CURRENT_USER\Console\%%SystemRoot%%_system32_cmd.exe" /f
    

    This is a sample batch that could be invoked ("batch_script.bat"):

    @echo off
    echo test!
    pause
    exit
    

    Don't forget the exit command at the end of your script if you want the reg delete line to run after the script execution.

提交回复
热议问题