使用PowerShell隐藏Windows终端控制台窗口

使用PowerShell隐藏Windows终端控制台窗口

我认为您试图隐藏错误的窗口。我尝试添加了WindowTitle,但它具有不正确(不是预期的)的值。

我将代码更改为只响铃10次,然后停止,并添加了在此处找到的一些代码:https://stackoverflow.com/a/40354761/724039

Add-Type @"

using System;

using System.Runtime.InteropServices;

public class UserWindows {

[DllImport("user32.dll")]

public static extern IntPtr GetWindowText(IntPtr hWnd, System.Text.StringBuilder text, int count);

}

"@

$stringbuilder = New-Object System.Text.StringBuilder 256

$windowcode = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'

$asyncwindow = Add-Type -MemberDefinition $windowcode -name Win32ShowWindowAsync -namespace Win32Functions -PassThru

$hwnd = (Get-Process -PID $pid).MainWindowHandle

$count = [UserWindows]::GetWindowText($hwnd, $stringbuilder, 256)

"The name of this window is: $($stringbuilder.ToString())"

if ($hwnd -ne [System.IntPtr]::Zero) {

$hidden = $asyncwindow::ShowWindowAsync($hwnd, 0)

}

$run = $true

$x=1

while ($x -le 10) {

[console]::beep(500,100)

Start-Sleep 1

$x++

}

当使用快捷方式启动以下内容时:pwsh.exe -File "d:\temp\beep1.ps1"

一个窗口会打开,上面显示文本The name of this window is:,我听到10声蜂鸣声,然后执行停止。

当在“Windows Powershell ISE”中执行时,该IDE的窗口会关闭。通过一些调试,我发现输出为“The name of this window is: Windows PowerShell ISE”。

我认为从获取WindowText的返回值应该类似于您的快捷方式标题。(但是,不幸的是,我无法解决此问题)

相关阅读

1磅等于多少厘米 excel1磅等于多少厘米
365bet比分直播

1磅等于多少厘米 excel1磅等于多少厘米

🕒 11-10 👁️‍🗨️ 9177
微粒贷逾期10天爆通讯录吗,催收后果有哪些
365bet比分直播

微粒贷逾期10天爆通讯录吗,催收后果有哪些

🕒 08-12 👁️‍🗨️ 480
从美味七七的倒下 反思生鲜电商发展之殇
365bet比分直播

从美味七七的倒下 反思生鲜电商发展之殇

🕒 01-11 👁️‍🗨️ 1785
云龙易购涉嫌诈骗
bet3365游戏

云龙易购涉嫌诈骗

🕒 09-24 👁️‍🗨️ 4923
Xbox登录异常无法进入游戏——4种快速解决方法
365游戏厅网页登录

Xbox登录异常无法进入游戏——4种快速解决方法

🕒 11-03 👁️‍🗨️ 809
蓝光软件
bet3365游戏

蓝光软件

🕒 02-06 👁️‍🗨️ 4983
[分享]【暖暖:皮肤盘点】稀有克隆皮肤来袭!盘点那些经历过的皮肤装扮与特色搭配
刚需客户怎么分类管理
365bet比分直播

刚需客户怎么分类管理

🕒 06-27 👁️‍🗨️ 8281
征途翅膀升级攻略 - 怎么提升征途翅膀等级及属性
bet3365游戏

征途翅膀升级攻略 - 怎么提升征途翅膀等级及属性

🕒 07-24 👁️‍🗨️ 9966