powershell - 将 powershell 控制台窗口移动到屏幕左侧的最佳方法是什么?

标签 powershell

尝试使用 PowerShell 脚本将当前事件的 powershell 窗口移动到屏幕左侧。

我找到了 this function ,但实际上并没有任何示例。

最佳答案

有趣有趣的问题。

如果你想移动窗口,你需要知道它的hwnd。对于控制台,您可以通过 kernel32.dll 中的 GetConsoleWindow 函数来完成。

检查这个脚本,它会将 powershell 控制台移动到左上角,大小为 500、500。

Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")] 
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int W, int H); '

$consoleHWND = [Console.Window]::GetConsoleWindow();
$consoleHWND
[Console.Window]::MoveWindow($consoleHWND,0,0,500,500);

如果你知道窗口的hwnd,你可以用这个窗口做很多事情。您可以在此处找到所有功能:https://msdn.microsoft.com/en-us/library/windows/desktop/ff468919(v=vs.85).aspx

但是这个脚本只适用于真正的 powershell 控制台,如果你从 Powershell ISE 启动它,hwnd 将为 0,因为 Powershell ISE 中没有真正的控制台。

关于powershell - 将 powershell 控制台窗口移动到屏幕左侧的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43043972/

相关文章:

object - $ null数组上的Compare-Object

file - 在 PowerShell 中获取文件版本

PowerShell摆脱最后的 `n` r?

powershell - 我不理解带有开始/处理/结束 block 的函数的参数绑定(bind)

string - Powershell字符串到数字功能?

powershell - Hyper-V:检查主机是否属于任何群集

powershell - PowerShell强制参数取决于另一个参数

c# - 序列化 WPF DataTemplates 和 {Binding Expressions}(来自 PowerShell?)

image - 使用Dockerfile构建镜像-未知指令

python - 忽略具有某些文件类型的文件夹