Откройте Firefox от powershell - PullRequest
       2

Откройте Firefox от powershell

0 голосов
/ 06 сентября 2018

Я могу открыть Internet Explorer, делая это, возможно ли сделать то же самое с Firefox?

$ie = new-object -comobject InternetExplorer.Application;

$ie.visible = $true;
#$ie2 = $ie.Width = 200;

$ie.top = 0; $ie.width = 1000; $ie.height = 600 ; $ie.Left = 200;

$ie.navigate('https://google.com');

Ответы [ 2 ]

0 голосов
/ 07 сентября 2018

См. Это обсуждение и ответ

Настройка размера и положения окна в PowerShell 5 и 6

# Call Firefox and set to window position on its process
Start-Process -FilePath 'C:\Program Files\Mozilla Firefox\firefox.exe'
Start-Sleep -Seconds 2
Set-Window -ProcessName firefox -x 1 -y 1 -Width 615 -Height 345 -Passthru
0 голосов
/ 06 сентября 2018

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")

Источники:

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...