Firefox имеет аргументы командной строки для ширины и высоты, но я не смог найти ничего для положения окна.
Это работает в 61.0.2. Возможно, вам придется изменить параметры на FindWindow()
в зависимости от вашего использования.
Обратите внимание, что это не самый надежный код, но он может удовлетворить ваши потребности.
& "C:\Program Files\Mozilla Firefox\firefox.exe" -width 1000 -height 600 https://google.com
$Assem = (
"System.Runtime.InteropServices"
)
$Source = @"
using System;
using System.Runtime.InteropServices; // For the P/Invoke signatures.
namespace Code42 {
public static class PositionWindowDemo
{
// P/Invoke declarations.
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOZORDER = 0x0004;
public static void MoveWindow(string name)
{
// Find (the first-in-Z-order) Notepad window.
IntPtr hWnd = FindWindow(null, name);
// If found, position it.
if (hWnd != IntPtr.Zero)
{
// Move the window to (0,0) without changing its size or position
// in the Z order.
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 200, SWP_NOSIZE | SWP_NOZORDER);
}
}
}
}
"@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
[Code42.PositionWindowDemo]::MoveWindow("Google - Mozilla Firefox")
Источники: