1

I've been using the following scrip (links changed) to open, resize and move two IE tabs on the screen. I've tried adapting the same script for Chrome/Firefox but i am missing something and i am not able to either open both pages in new tabs, or even move/resize the windows.

<# :
@echo off
setlocal
cls
set "POWERSHELL_BAT_ARGS=%*"
if defined POWERSHELL_BAT_ARGS set "POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%"
endlocal & powershell -NoLogo -NoProfile -Command "$_ = $input; Invoke-Expression $( '$input = $_; $_ = \"\"; $args = @( &{ $args } %POWERSHELL_BAT_ARGS% );' + [String]::Join( [char]10, $( Get-Content \"%~f0\" ) ) )"
goto :EOF
#>

Add-Type @"
    using System;
    using System.Runtime.InteropServices;

    public class Win32 { 
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    }
"@

Function MoveAndResize ($browser)
{

    Switch($browser){
        WINDOW1{
            $browser_path="C:\Program Files\Internet Explorer\IEXPLORE.EXE"
            $url = "https://www.google.com/" 
            $pos_x = 0
            $pos_y = 0
            $window_x = 975
            $window_y = 1080
            break
        }
        WINDOW2{
            $browser_path="C:\Program Files\Internet Explorer\IEXPLORE.EXE"
            $url = "https://www.bing.com/"
            $pos_x = 960
            $pos_y = 0
            $window_x = 975
            $window_y = 1080
            break
        }
        default {continue}
    }

    Start-Process $browser_path $url
    Start-Sleep -S 1

    $browser = (Get-Process | where {$_.Path -eq $browser_path}).MainWindowHandle

    [Win32]::MoveWindow($browser, $pos_x, $pos_y, $window_x, $window_y, $true)
}

MoveAndResize "WINDOW1"
MoveAndResize "WINDOW2"

As i am not a mastermind, and this is way over my batch knowledge i've got the following questions: Is there any reworking over the code/ anything or any tips to get it working? Any code that could be removed to make it smaller? How could i make it open the pages in new tabs?

Zeta Reactor
  • 85
  • 1
  • 7
  • I never thought I'd see a question about [code I wrote](https://stackoverflow.com/a/34602815/4158862). This isn't meant for tabs, it's meant for completely separate windows. The only way to open a new tab would be if IE had an argument that allowed that. Window sizes and locations are hard-coded in the pos_x/pos_y/window_x/window_y variables. – SomethingDark Apr 27 '20 at 05:19
  • Haha, i've recieved this from someone else, i knew i've seen it in somewhere but i wasn't sure where exactly. What i am trying to do is also allow Chrome to open two new windows, in IE it opens each link in a new window and i'm not sure where exactly i could pass/what argument to pass to get it working like that. – Zeta Reactor Apr 27 '20 at 13:41

1 Answers1

1

The best way to easily open a new tab in any browser:

START "<ApplicationName>" <URL>

Leaving the Application Name empty will open the default browser.

Hope this helps.