编辑:如何指定命令提示符的字体和窗口的大小?我正在使用 Windows 7 专业版。好的。对不起,我正在尝试使用命令来执行上述操作,因此我不接受那些“按属性”的答案。
如果要以编程方式更改控制台字体大小,请参阅此页面和此页面。您基本上必须将该模块源从 technet 页面复制粘贴到SetConsoleFont.psm1本地计算机上调用的新文件中。把它放到同名文件夹中,没有 ext(所以它变成了SetConsoleFont\SetConsoleFont.psm1)。从命令行,powershell -command "echo $env:PSModulePath"查看您应该将该SetConsoleFont\文件夹放在哪里(可能在 中%userprofile%\Documents\WindowsPowerShell\Modules)。
如果您想在批处理脚本中包含该 technet 脚本并[module_path_dir]\SetConsoleFont\SetConsoleFont.psm1在用户的机器上创建批处理脚本,我建议使用批处理脚本 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 one-liner 用于更改缓冲区(回滚历史记录)大小。
:: 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
Run Code Online (Sandbox Code Playgroud)