找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 35|回复: 0

[问题求助] 怎样设置powershell控制台窗口的宽度,高度,居中

[复制链接]
发表于 昨天 13:12 | 显示全部楼层 |阅读模式
本帖最后由 小白龙 于 2026-3-23 16:21 编辑

我想把powershell控制台的窗口设置为固定大小, 宽度为1024像素, 高度为360像素, 然后窗口水平居中,
但是powershell控制台的窗口大小是由下图的三个参数(屏幕缓冲区,窗口大小, 窗口位置)共同决定的, 而且有时调整不了宽度或高度(选定图中属性布局设置中的那两个复选框时)
aaa.png

下面有个文章很详细:
https://blog.csdn.net/2401_83950228/article/details/138104663

下面是个不完善的代码, 求大佬改进.


  1. #@&cls&powershell "gc '%~f0'|out-string|iex"&pause&exit

  2. Add-Type @'
  3. using System.Runtime.InteropServices;
  4. public static class WinApi{
  5.         [DllImport("user32.dll")] public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
  6.         [DllImport("kernel32.dll")] public static extern uint GetConsoleWindow();
  7. }
  8. '@
  9. Add-Type -Ass System.Windows.Forms
  10. $w = [Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
  11. $h = [WinApi]::GetConsoleWindow()
  12. [WinApi]::SetWindowPos($h, $null, ($w-1060)/2, 20, 1060, 386, 0)

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-24 03:48

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表