Add-Type -AssemblyName System.Windows.Forms
Add-Type @'
using System;
using System.Runtime.InteropServices;
public class WinMove {
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(
IntPtr hWnd, IntPtr after,
int X, int Y, int W, int H, uint flags);
}
'@
# Знаходимо другий монітор
$screens = [System.Windows.Forms.Screen]::AllScreens
if ($screens.Count -lt 2) {
Write-Host "Другий монітор не знайдено!"
Read-Host "Натисни Enter для виходу"
exit
}
$monitor = $screens[1]
$bounds = $monitor.Bounds
function Start-CmdWindow {
param(
[string]$Title,
[string]$Command,
[int]$X,
[int]$Y,
[int]$Width = 600,
[int]$Height = 280
)
# Перетворюємо локальні координати на координати Windows
$absoluteX = $bounds.X + $X
$absoluteY = $bounds.Y + $Y
$p = Start-Process "$env:WINDIR\System32\cmd.exe" `
-ArgumentList "/k title $Title & $Command" `
-PassThru
for ($i = 0; $i -lt 50; $i++) {
$p.Refresh()
if ($p.MainWindowHandle -ne 0) { break }
Start-Sleep -Milliseconds 1
}
if ($p.MainWindowHandle -ne 0) {
[void][WinMove]::SetWindowPos(
$p.MainWindowHandle,
[IntPtr]::Zero,
$absoluteX, $absoluteY,
$Width, $Height, 0
)
}
else {
Write-Host "Не вдалося знайти вікно $Title"
}
}
Start-CmdWindow -Title "check Internet" -Command "ping 8.8.8.8 -t" -X 10 -Y 1650
Start-CmdWindow -Title "check Anten" -Command "ping 192.168.1.162 -t" -X 540 -Y 1650
Start-CmdWindow -Title "check Starlink" -Command "ping 192.168.100.1 -t" -X 10 -Y 1420
Start-CmdWindow -Title "check VPN" -Command "ping 10.6.1.226 -t" -X 540 -Y 1420