Firefox has command-line arguments for width and height, but I could not find anything for window position.
This works in 61.0.2. You may have to modify the parameters to FindWindow()
based on your usage.
Note that this is not the most robust code ever, but it may suit your needs.
& "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")
Sources: