控制台窗口不被W * H以像素为单位,但在行和列。部分地,物理尺寸将取决于用户定义的字体和大小。
最简单的解决方案是使用mode
命令增加行数和/或列数。您还可以使用PowerShell助手来增加滚动缓冲区。如下是一个批处理函数,我使用了几次来处理所有这些值。
:consize <columns> <lines> <scrolllines>
:: change console window dimensions and buffer
mode con: cols=%1 lines=%2
powershell -noprofile "$W=(get-host).ui.rawui; $B=$W.buffersize; $B.height=%3; $W.buffersize=$B"
goto :EOF
的:consize
功能发生在脚本的底部,最终exit /b
或goto :EOF
后,在主脚本运行时结束。 See this page有关批处理功能的更多示例。
实例:
call :consize 80 33 10000
...将扩大窗口为80列和33行,然后展开垂直滚动缓冲器10000线。
下面是一个更完整的批处理+的PowerShell脚本混合动力车将在窗口移动到0,0那么它的宽度和高度改变到最大的行和列的屏幕可以容纳。我不得不尝试一下$max.Height
和$max.Width
值,所以我不确定不同的显示分辨率和不同的字体大小会如何影响脚本。不过,它应该足够接近政府的工作。
<# : batch portion
@echo off & setlocal
call :maximize
rem /* ###############################
rem Your main batch code goes here.
rem ############################### */
goto :EOF
:maximize
set "scrollLines=10000"
powershell -noprofile "iex (${%~f0} | out-string)"
goto :EOF
rem // end batch/begin PowerShell hybrid code #>
# Moving the window to coordinates 0,0 requires importing a function from user32.dll.
add-type user32_dll @'
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int x, int y, int cx, int cy, uint uFlags);
'@ -namespace System
# Walk up the process tree until we find a window handle
$id = $PID
do {
$id = (gwmi win32_process -filter "ProcessID='$id'").ParentProcessID
$hwnd = (ps -id $id).MainWindowHandle
} while (-not $hwnd)
# This is where the window moves!
[void][user32_dll]::SetWindowPos($hwnd, [IntPtr]::Zero, 0, 0, 0, 0, 0x41)
# Maximize the window
$console = (get-host).ui.rawui
$max = $console.MaxPhysicalWindowSize
$max.Height -= 1 # account for the titlebar
$max.Width -= 5 # account for the scrollbar
$buffer = $max
$buffer.Height = $env:scrollLines
$console.BufferSize = $buffer
$console.WindowSize = $max
这不是DOS,它是Windows命令行!批处理脚本中没有'SendKeys'命令。但您可能对[AutoIt](http://www.autoit.com)或[AutoHotkey](http://www.autohotkey.com)感兴趣... – aschipfl
对不起,[AutoIt](http:// www.autoitscript.com)链接是错误的 - 现在它是正确的... – aschipfl
您可以使用'echo ... >> x.vbs'创建'.vbs'文件在该vbs中添加'sendkeys'命令&call thet与wscript。 – anishsane