批处理之家's Archiver

5i365 发表于 2022-4-9 12:42

PowerShell隐藏命令行窗口的滚动条

下面的代码,可以隐藏命令行窗口的标题栏, 但是滚动条没有隐藏,
另外好像还有个内嵌的乱掉的滚动条, 怎样把它们也隐藏, 求路过高手指教, 提前感谢[code]#@&cls&powershell "type '%~0'|out-string|iex"&pause&exit

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

[void][WinApi]::SetWindowLong(([WinApi]::GetConsoleWindow()), -16, 369164288)[/code]

idwma 发表于 2022-4-9 20:53

[code][console]::BufferHeight=[console]::WindowHeight
[console]::BufferWidth=[console]::WindowWidth[/code]

5i365 发表于 2022-4-10 06:44

[i=s] 本帖最后由 5i365 于 2022-4-10 06:45 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254030&ptid=62277]2#[/url] [i]idwma[/i] [/b]


   感谢和大侠支招,
我加在代码的前面或后面都试了, 还是有框下面贴子好像是 相同的问题, 但是代码太多了, 看不懂
https://www.manongdao.com/article-1162439.html

idwma 发表于 2022-4-10 16:21

绕一下[code]#@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
[console]::BufferHeight=[console]::WindowHeight
[console]::BufferWidth=[console]::WindowWidth
[console]::BackgroundColor=0xf
[console]::ForegroundColor=0x0
Add-Type -Ty @'
    using System.Runtime.InteropServices;
    public static class WinApi{
        [DllImport("kernel32.dll")] public static extern uint GetConsoleWindow();
        [DllImport("User32.dll")] public static extern int SetWindowLong(uint hWnd,int nIndex,int dwNewLong);
        [DllImport("User32.dll")] public static extern bool SetWindowPos(uint hWnd,uint hAfter,uint x,uint y,uint cx,uint cy,uint flags);
    }
'@
$a=[WinApi]::GetConsoleWindow()
[void][WinApi]::SetWindowLong($a, -16, 369164288)
[WinApi]::SetWindowPos($a,0,0,0,0,0,0x0087)
[WinApi]::SetWindowPos($a,0,0,0,0,0,0x0047)
cls[/code]

5i365 发表于 2022-4-10 17:07

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254080&ptid=62277]4#[/url] [i]idwma[/i] [/b]


   大侠高, 好像是把白色底色和白色的滚动条浑然一体了, 这样就只能白底黑字了吧, 能黑底白字吗? :lol

idwma 发表于 2022-4-10 19:11

[i=s] 本帖最后由 idwma 于 2022-4-10 20:37 编辑 [/i]

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

5i365 发表于 2022-4-10 19:46

[i=s] 本帖最后由 5i365 于 2022-4-10 19:48 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254088&ptid=62277]6#[/url] [i]idwma[/i] [/b]

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

以前,将(屏宽-第一个值)/2, 第二个值为0  可以顶部居中对齐, 现在还能实现吗?

idwma 发表于 2022-4-10 20:29

[i=s] 本帖最后由 idwma 于 2022-4-10 20:38 编辑 [/i]

这里其实是搞错了,可以随便填两个数位置是不会变的
应该可以用以前went大的那个代码来居中
好像也不用那么复杂简单的修改了一下

5i365 发表于 2022-4-10 22:05

[i=s] 本帖最后由 5i365 于 2022-4-10 22:09 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254094&ptid=62277]8#[/url] [i]idwma[/i] [/b]


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

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

$l=((Get-WmiObject win32_desktopmonitor).ScreenWidth[color=#ff0000]-800)[/color][size=12px]/[/size][color=#ff0000][size=12px]2[/size][/color]
$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,[color=#ff0000]800,100[/color],2)
[console]::BufferHeight=[console]::WindowHeight
[console]::BufferWidth=[console]::WindowWidth

娜美 发表于 2022-4-15 22:40

想跟贴问一下,  双击时可以静默的转到后台执行吗  ?   就是不弹出cmd窗口了,  直接转到后台进程执行脚本

5i365 发表于 2022-4-16 07:54

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254320&ptid=62277]10#[/url] [i]娜美[/i] [/b]


   感觉应该可以, 看到过有API可以把整窗口隐藏了, 不过还是会闪一下
但是还是有个窗口好点, 可以看运行后的出错信息

娜美 发表于 2022-4-16 11:08

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=254325&ptid=62277]11#[/url] [i]5i365[/i] [/b]



可以静悄悄的
    set ws=wscript.createobject("wscript.shell")
ws.run "tmp.bat",0

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.