【发布时间】:2014-11-25 06:40:19
【问题描述】:
编辑:如何指定命令提示符的字体和窗口的大小?我正在使用 Windows 7 专业版。 好的。对不起,我正在尝试使用命令来做上述事情,所以我不接受那些“按属性”的答案。
【问题讨论】:
-
也许this 可以提供帮助
标签: batch-file
编辑:如何指定命令提示符的字体和窗口的大小?我正在使用 Windows 7 专业版。 好的。对不起,我正在尝试使用命令来做上述事情,所以我不接受那些“按属性”的答案。
【问题讨论】:
标签: batch-file
如果您想以编程方式更改控制台字体大小,请参阅this page 和this 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
【讨论】:
Import 命令和Get-ConsoleFontInfo 函数没有返回任何内容。有些在运行Set-ConsoleFont 函数时也会出现权限错误。
如果您创建 cmd.exe 的快捷方式,您可以右键单击它并选择“属性”。在这里可以设置字体、颜色、窗口和缓冲区大小等。
【讨论】: