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

[问题求助] PowerShell隐藏命令行窗口的滚动条

[复制链接]
发表于 2022-4-9 12:42:45 | 显示全部楼层 |阅读模式
下面的代码,可以隐藏命令行窗口的标题栏, 但是滚动条没有隐藏,
另外好像还有个内嵌的乱掉的滚动条, 怎样把它们也隐藏, 求路过高手指教, 提前感谢
  1. #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit

  2. Add-Type -Ty @'
  3.     using System.Runtime.InteropServices;
  4.     public static class WinApi{
  5.         [DllImport("kernel32.dll")] public static extern uint GetConsoleWindow();
  6.         [DllImport("User32.dll")] public static extern int SetWindowLong(uint hWnd,int nIndex,int dwNewLong);
  7.     }
  8. '@

  9. [void][WinApi]::SetWindowLong(([WinApi]::GetConsoleWindow()), -16, 369164288)
复制代码
发表于 2022-4-9 20:53:48 | 显示全部楼层
  1. [console]::BufferHeight=[console]::WindowHeight
  2. [console]::BufferWidth=[console]::WindowWidth
复制代码
 楼主| 发表于 2022-4-10 06:44:27 | 显示全部楼层
本帖最后由 5i365 于 2022-4-10 06:45 编辑

回复 2# idwma


   感谢和大侠支招,
我加在代码的前面或后面都试了, 还是有框下面贴子好像是 相同的问题, 但是代码太多了, 看不懂
https://www.manongdao.com/article-1162439.html
发表于 2022-4-10 16:21:54 | 显示全部楼层
绕一下
  1. #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
  2. [console]::BufferHeight=[console]::WindowHeight
  3. [console]::BufferWidth=[console]::WindowWidth
  4. [console]::BackgroundColor=0xf
  5. [console]::ForegroundColor=0x0
  6. Add-Type -Ty @'
  7.     using System.Runtime.InteropServices;
  8.     public static class WinApi{
  9.         [DllImport("kernel32.dll")] public static extern uint GetConsoleWindow();
  10.         [DllImport("User32.dll")] public static extern int SetWindowLong(uint hWnd,int nIndex,int dwNewLong);
  11.         [DllImport("User32.dll")] public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
  12.     }
  13. '@
  14. $a=[WinApi]::GetConsoleWindow()
  15. [void][WinApi]::SetWindowLong($a, -16, 369164288)
  16. [WinApi]::SetWindowPos($a,0,0,0,0,0,0x0087)
  17. [WinApi]::SetWindowPos($a,0,0,0,0,0,0x0047)
  18. cls
复制代码
 楼主| 发表于 2022-4-10 17:07:58 | 显示全部楼层
回复 4# idwma


   大侠高, 好像是把白色底色和白色的滚动条浑然一体了, 这样就只能白底黑字了吧, 能黑底白字吗?
发表于 2022-4-10 19:11:19 | 显示全部楼层
本帖最后由 idwma 于 2022-4-10 20:37 编辑

再绕一下
  1. #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
  2. [console]::BufferHeight=[console]::WindowHeight
  3. [console]::BufferWidth=[console]::WindowWidth
  4. Add-Type -Ty @'
  5.     using System.Runtime.InteropServices;
  6.     public static class WinApi{
  7.         [DllImport("kernel32.dll")] public static extern uint GetConsoleWindow();
  8.         [DllImport("User32.dll")] public static extern int SetWindowLong(uint hWnd,int nIndex,int dwNewLong);
  9.         [DllImport("User32.dll")] public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
  10.     }
  11. '@
  12. $l=(Get-WmiObject win32_videocontroller).CurrentHorizontalResolution/2-200
  13. $a=[WinApi]::GetConsoleWindow()
  14. [void][WinApi]::SetWindowLong($a, -16, 369164288)
  15. [WinApi]::SetWindowPos($a,0,$l,0,0,0,1)
  16. [WinApi]::SetWindowPos($a,0,$l,0,400,500,2)
  17. [console]::BufferHeight=[console]::WindowHeight
  18. [console]::BufferWidth=[console]::WindowWidth
复制代码

评分

参与人数 1技术 +1 收起 理由
5i365 + 1 技术牛X, 乐于分享!

查看全部评分

 楼主| 发表于 2022-4-10 19:46:41 | 显示全部楼层
本帖最后由 5i365 于 2022-4-10 19:48 编辑

回复 6# idwma

现在有个新问题, 下面这两个值应该是窗口位置,
[console]::WindowLeft,[console]::WindowTop

以前,将(屏宽-第一个值)/2, 第二个值为0  可以顶部居中对齐, 现在还能实现吗?
发表于 2022-4-10 20:29:40 | 显示全部楼层
本帖最后由 idwma 于 2022-4-10 20:38 编辑

这里其实是搞错了,可以随便填两个数位置是不会变的
应该可以用以前went大的那个代码来居中
好像也不用那么复杂简单的修改了一下
 楼主| 发表于 2022-4-10 22:05:33 | 显示全部楼层
本帖最后由 5i365 于 2022-4-10 22:09 编辑

回复 8# idwma


went大侠那个居中的代码感觉有点长,下面这样也能居中了,
但是有的代码是重复的, 感觉可能还能优化,

这效果实际用处也不大, 以前发过贴子求BAT命令行窗口居中, 没想到现在用PS实现了, 感觉很有趣

$l=((Get-WmiObject win32_desktopmonitor).ScreenWidth-800)/2
$a=[WinApi]::GetConsoleWindow()
[void][WinApi]::SetWindowLong($a, -16, 369164288)
[void][WinApi]::SetWindowPos($a,0,$l,0,0,0,1)
[void][WinApi]::SetWindowPos($a,0,$l,0,800,100,2)
[console]::BufferHeight=[console]::WindowHeight
[console]::BufferWidth=[console]::WindowWidth
发表于 2022-4-15 22:40:05 | 显示全部楼层
想跟贴问一下,  双击时可以静默的转到后台执行吗  ?   就是不弹出cmd窗口了,  直接转到后台进程执行脚本
 楼主| 发表于 2022-4-16 07:54:54 | 显示全部楼层
回复 10# 娜美


   感觉应该可以, 看到过有API可以把整窗口隐藏了, 不过还是会闪一下
但是还是有个窗口好点, 可以看运行后的出错信息
发表于 2022-4-16 11:08:39 | 显示全部楼层
回复 11# 5i365



可以静悄悄的
    set ws=wscript.createobject("wscript.shell")
ws.run "tmp.bat",0
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 04:13 , Processed in 0.022726 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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