执行批处理文件时指定命令提示符的大小

时间:2014-11-25 06:40:20

标签: batch-file

编辑:如何指定命令提示符的字体和窗口的大小?我使用的是Windows 7专业版。 确定。对不起,我试图用命令来做上述事情,所以我不接受那些"按下属性"答案。

2 个答案:

答案 0 :(得分:3)

如果您想以编程方式更改控制台字体大小,请参阅this pagethis page。您基本上必须将来自technet页面的模块源复制到本地计算机上名为SetConsoleFont.psm1的新文件中。将它放入一个没有ext的同名文件夹中(因此它变为SetConsoleFont\SetConsoleFont.psm1)。从命令行powershell -command "echo $env:PSModulePath"查看您应该将SetConsoleFont\文件夹放在哪里(可能在%userprofile%\Documents\WindowsPowerShell\Modules中)。

如果您想在批处理脚本中包含该technet脚本并让批处理脚本在用户的计算机上创建[module_path_dir]\SetConsoleFont\SetConsoleFont.psm1,我建议batch script heredoc是一种简单的方法它并动态写入。

使用模块路径中的模块,您现在可以从cmd行使用它。

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Get-ConsoleFontInfo | Format-Table -AutoSize}"

将显示控制台可用字体大小的表格。从nFont列中选择一个并按以下方式激活它:

powershell -command "&{set-executionpolicy remotesigned; Import-Module SetConsoleFont; Set-ConsoleFont 6}"

如果您只想调整控制台窗口和缓冲区的大小,那就简单多了。不需要模块或导入或执行策略覆盖。 mode con: cols=n1 lines=n2将更改窗口尺寸,并且有一个PowerShell单行程序用于更改缓冲区(回滚历史记录)大小。

:: Resize the console window and increase the buffer to 10000 lines
call :consize 80 33 80 10000

:: put the main part of your bat script here.
:: script
:: script
:: script
:: etc.

goto :EOF

:consize <columns> <lines> <buffercolumns> <bufferlines>
:: change console window dimensions and buffer
mode con: cols=%1 lines=%2
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
goto :EOF

答案 1 :(得分:0)

如果您创建cmd.exe的快捷方式,则无法右键单击它并选择“属性”。在这里,您可以设置字体,颜色,窗口和缓冲区大小等。