在指定屏幕/坐标处打开浏览器窗口

在指定屏幕/坐标处打开浏览器窗口

客户为每个工作站设置了 6 个屏幕,并希望在启动或调用快捷方式时在每个屏幕上自动打开 Web 应用程序的各个页面。(目标 Web 浏览器可能是 Chrome)。

我想知道是否可以使用 Javascriptwindow.open来实现这一点,但一个可能的障碍是客户可能希望在打开弹出窗口阻止程序的情况下进行选项卡式浏览。(好的,这些可以被覆盖,但这种配置目前不受我们控制......)

所以问题是:是否可以编写一个脚本(例如批处理文件)来在 6 个屏幕内的指定坐标处打开浏览器的多个实例(每个实例指向不同的 URL)?

[这基本上是同一个问题https://askubuntu.com/questions/68354/is-there-any-way-to-specify-which-workspace-and-or-window-to-launch-a-program-in但适用于 Windows 而不是 Ubuntu。

答案1

刚刚发现这个:

https://stackoverflow.com/questions/10392620#20466454

这并不是我想要的,因为它依赖于第三方工具和相当复杂的批处理脚本,但这是我迄今为止得到的最好的......

编辑:根据fixer1234的要求,链接答案的相关部分复制如下。


此演示批处理文件将在双显示器桌面的另一台(非主)显示器上并排打开两个 Explorer 窗口,并使其居中显示。请阅读批处理文件中的说明。

注意:对于此演示,我假设左侧显示器为 Monitor-1(主活动显示器,包含任务栏),右侧显示器为 Monitor-2(非主活动显示器)。如果您的设置不同,请调整脚本。

所用工具:
1.监控信息视图作者:Nir Sofer(41 千字节)..............主页
2.多显示器工具作者:Nir Sofer(102 千字节)...........主页
3.近红外命令作者:Nir Sofer(43 千字节)...........................主页
4.批处理文件 (6 千字节)...............................................见下文

将所有四个文件收集到一个目录中。
这是批处理文件,可在任何 Windows 系统上运行(运行它以进行即时演示):

@echo off
REM ----- GIVE THIS CONSOLE WINDOW TITLE A UNIQUE STRING ID
title OPEN-2-EXPLORER-WINDOWS-SIDE-BY-SIDE-AND-CENTERED-ON-SCREEN-AT-MONITOR-2-OF-A-MULTI-MONITOR-DESKTOP___20140101024519
pushd %~dp0

REM ----- HIDE THIS CONSOLE WINDOW (HOOKS THE WINDOW TITLE)
nircmd.exe win hide ititle "OPEN-2-EXPLORER-WINDOWS-SIDE-BY-SIDE-AND-CENTERED-ON-SCREEN-AT-MONITOR-2-OF-A-MULTI-MONITOR-DESKTOP___20140101024519"

REM ********************** DESCRIPTION ************************************
REM ** This script opens one or more windows with specified screen properties
REM ** at a chosen monitor of a multi-monitor desktop. The "X/Y position" and
REM ** "W/H size" of the windows are auto-set by this script and the monitor
REM ** resolutions are auto-calculated to suit. 
REM ** 'MonitorInfoView.exe' is the helper tool used to isolate the resolution
REM ** info of the primary monitor (containing the taskbar).
REM ** 'MultiMonitorTool.exe' is the helper tool used to capture the 
REM ** resolution info of all monitors and for isolating the resolution info
REM ** of the other (non-primary) monitor.
REM ** 'nircmd.exe' is the tool performing all the display trickery.
REM **
REM ** To tweak this script, go to the code section named:
REM ** >>>>> USER INPUT/PREFERENCES ARE ALL SET HERE <<<<<
REM ***********************************************************************

REM ----- CLEAR ANY PREVIOUS JOB OUTPUTS IF THEY EXIST
if exist ~TMP.TXT type NUL > ~TMP.TXT
if exist ~TMP2.TXT type NUL > ~TMP2.TXT

REM ----- OUTPUT THE PRIMARY MONITOR (MONITOR-1) INFORMATION TO A TEXT FILE
MonitorInfoView.exe /hideinactivemonitors 1 /stext ~TMP.TXT

REM ----- ISOLATE THE RESOLUTION LINE OF MONITOR-1, REMOVING ALL THE OTHER LINES IN THE TEXT FILE
for /f "delims=" %%A in ('type "~TMP.TXT" ^|find.exe /i "Maximum Resolution"') do echo %%A>~TMP.TXT

REM ----- GET THE RESOLUTION NUMBERS OF MONITOR-1, AND SET THEM AS VARIABLES
for /f "tokens=3,4 delims=:X " %%A in ('type "~TMP.TXT"') do (
set _M1_SCREENW_=%%A
set _M1_SCREENH_=%%B
)

REM ----- OUTPUT INFO OF ALL MONITORS TO TEXT FILE
MultiMonitorTool.exe /stext ~TMP.TXT

REM ----- TRY REMOVING MONITOR-1 RESOLUTION LINE (KEEPING MONITOR-2 RESOLUTION LINE)
find.exe /i /v "%_M1_SCREENW_% X %_M1_SCREENH_%" < ~TMP.TXT > ~TMP2.TXT

REM ----- TRY ISOLATING MONITOR-2 RESOLUTION LINE (REMOVING ALL THE OTHER LINES IN THE TEXT FILE)
for /f "delims=" %%A in ('type "~TMP2.TXT" ^|find.exe /i "Maximum Resolution"') do echo %%A>~TMP2.TXT

REM ----- CONDITIONALLY GET THE RESOLUTION NUMBERS OF MONITOR-2, AND SET THEM AS VARIABLES ...
REM ----- CASE(A): IF MONITORS HAVE SAME RESOLUTION, ASSUME NO LINES HAVE STRING "Maximum Resolution". 
REM ----- CASE(B): IF MONITORS HAVE DIFFERENT RESOLUTION, ASSUME ONE LINE HAS STRING "Maximum Resolution".
find.exe /i /c "Maximum Resolution" ~TMP2.TXT
if %ERRORLEVEL% equ 1 (
set _M2_SCREENW_=%_M1_SCREENW_%&set _M2_SCREENH_=%_M1_SCREENH_%
) else (
for /f "tokens=3,4 delims=:X " %%A in ('type "~TMP2.TXT"') do set _M2_SCREENW_=%%A&set _M2_SCREENH_=%%B
)    


REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
REM >>>>>>>>>> USER INPUT/PREFERENCES ARE ALL SET HERE [BEGIN] <<<<<<<<<<<<

REM ----- MONITOR-2 LEFT WINDOW PROPERTIES

    set _M2_WINLEFT_=%SYSTEMDRIVE%
    set /a _M2_WINLEFTW_=(%_M2_SCREENW_% / 3) + 50
    set /a _M2_WINLEFTH_=(%_M2_SCREENH_% / 2) + 200
    set /a _M2_WINLEFTX_=(%_M1_SCREENW_%) + (%_M2_SCREENW_% - %_M2_WINLEFTW_%) / 5
    set /a _M2_WINLEFTY_=(%_M2_SCREENH_% - %_M2_WINLEFTH_%) / 2

REM ----- MONITOR-2 RIGHT WINDOW PROPERTIES

    set _M2_WINRIGHT_=%USERPROFILE%
    set /a _M2_WINRIGHTW_=(%_M2_SCREENW_% / 3) + 50
    set /a _M2_WINRIGHTH_=(%_M2_SCREENH_% / 2) + 200
    set /a _M2_WINRIGHTX_=(%_M2_WINLEFTX_%) + (%_M2_WINLEFTW_%)
    set /a _M2_WINRIGHTY_=(%_M2_SCREENH_% - %_M2_WINRIGHTH_%) / 2

REM ----- ADJUST THE WAIT TIME (MILLISECONDS) BETWEEN EACH WINDOW LAUNCH.
REM ----- IF TOO QUICK, THE FOLLOWING WINDOW WILL NOT SET IN THE CORRECT SCREEN POSITION.
REM ----- | FOR FAST SYSTEM: TRY 200 | NORMAL SYSTEM: TRY 400-600 | BLOATED SYSTEM: TRY 800-1200+

    set _WAITTIME_=400

REM ----- ON WINDOWS NT5 (XP, 2000), RUNNING EXPLORER WITH THE 'N' SWITCH WOULD RELIABLY GIVE
REM ----- YOU 1-PANE VIEW (HIDDEN LEFT NAV PANE). ALSO, SHOWING/HIDING OF THE LEFT NAV PANE WAS
REM ----- INSTANTLY TOGGLED BY AN ICON ON THE EXPLORER GUI TOOLBAR.
REM ----- ON WINDOWS NT6 (VISTA, 7), EXPLORER WILL NOT OBEY YOUR COMMANDS AT ALL TIMES AND IT
REM ----- IS A "PITA" TO CONTROL THE GRAPHIC USER INTERFACE. 
REM ----- THIS INPUT SECTION IS A WORKAROUND TO FORCE AN INSTANCE OF NT6 EXPLORER TO BE
REM ----- TOGGLED TO A SPECIFIED VIEW.
REM ----- |
REM ----- | INSERT ONE OF THESE VALUES INTO THE VARIABLE _EXPLORER_VIEW_MYPREF_
REM ----- | | FOR EXPLORER 2-PANE VIEW (SHOW LEFT NAVPANE):  150100000100000000000000E5010000
REM ----- | | FOR EXPLORER 1-PANE VIEW (HIDE LEFT NAVPANE):  1501000000000000000000007B020000

    set _EXPLORER_VIEW_MYPREF_=1501000000000000000000007B020000

REM >>>>>>>>>> USER INPUT/PREFERENCES ARE ALL SET HERE [END] <<<<<<<<<<<<<<
REM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


REM ----- RUN THE TASK . . .

REM ----- REGKEY 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules' DOES NOT EXIST IN NT5 OR EARLIER
REM ----- BUT TO ELIMINATE DOUBT WE WILL PERFORM A CONDITIONAL VERSION CHECK
for /f "tokens=2 delims=[]" %%A in ('ver') do set _THIS_OS_VERSTRING_=%%A
set _THIS_OS_VERSTRING_=%_THIS_OS_VERSTRING_:Version =%
for /f "tokens=1,2,3* delims=." %%A in ("%_THIS_OS_VERSTRING_%") do set _THIS_OS_MAJORVERSION_=%%A
if %_THIS_OS_MAJORVERSION_% leq 5 goto SKIP1

set _EXPLORER_VIEW_REGKEY_=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Modules\GlobalSettings\Sizer
set _EXPLORER_VIEW_REGVAL_=PageSpaceControlSizer
if exist ~TMP.TXT type NUL > ~TMP.TXT
reg.exe query %_EXPLORER_VIEW_REGKEY_% > ~TMP.TXT
if %ERRORLEVEL% equ 1 goto SKIP1
for /f "delims=" %%A in ('type "~TMP.TXT" ^|find.exe /i "%_EXPLORER_VIEW_REGVAL_%"') do echo %%A>~TMP.TXT
for /f "tokens=1-3 delims= " %%A in ('type "~TMP.TXT"') do set _EXPLORER_VIEW_SYSTEMPREF_=%%C
reg.exe add %_EXPLORER_VIEW_REGKEY_% /v %_EXPLORER_VIEW_REGVAL_% /t REG_BINARY /d %_EXPLORER_VIEW_MYPREF_% /f 2>nul >nul
nircmd.exe wait %_WAITTIME_%

:SKIP1
nircmd.exe exec show "explorer.exe" /n,%_M2_WINLEFT_%
nircmd.exe wait %_WAITTIME_%
nircmd.exe win setsize foreground %_M2_WINLEFTX_% %_M2_WINLEFTY_% %_M2_WINLEFTW_% %_M2_WINLEFTH_%
nircmd.exe wait %_WAITTIME_%
nircmd.exe exec show "explorer.exe" /n,%_M2_WINRIGHT_%
nircmd.exe wait %_WAITTIME_%
nircmd.exe win setsize foreground %_M2_WINRIGHTX_% %_M2_WINRIGHTY_% %_M2_WINRIGHTW_% %_M2_WINRIGHTH_%


REM ----- RESET SYSTEM PREF, CLEAR MEMORY, CLEANUP, QUIT . . .

find.exe /i /c "%_EXPLORER_VIEW_REGVAL_%" ~TMP.TXT
if %ERRORLEVEL% equ 1 goto SKIP2
nircmd.exe wait %_WAITTIME_%
nircmd.exe wait %_WAITTIME_%
reg.exe add %_EXPLORER_VIEW_REGKEY_% /v %_EXPLORER_VIEW_REGVAL_% /t REG_BINARY /d %_EXPLORER_VIEW_SYSTEMPREF_% /f 2>nul >nul
:SKIP2
set _M1_SCREENW_=
set _M1_SCREENH_=
set _M2_SCREENW_=
set _M2_SCREENH_=
set _M2_WINLEFT_=
set _M2_WINLEFTX_=
set _M2_WINLEFTY_=
set _M2_WINLEFTW_=
set _M2_WINLEFTH_=
set _M2_WINRIGHT_=
set _M2_WINRIGHTX_=
set _M2_WINRIGHTY_=
set _M2_WINRIGHTW_=
set _M2_WINRIGHTH_=
set _WAITTIME_=
set _THIS_OS_VERSTRING_=
set _THIS_OS_MAJORVERSION_=
set _EXPLORER_VIEW_REGKEY_=
set _EXPLORER_VIEW_REGVAL_=
set _EXPLORER_VIEW_MYPREF_=
set _EXPLORER_VIEW_SYSTEMPREF_=
del /f /q ~TMP.TXT
del /f /q ~TMP2.TXT
popd
exit

答案2

实用程序“CMDOW 命令行窗口实用程序”可能也能正常工作,与控制批处理文件结合使用来打开和定位浏览器窗口。

http://www.commandline.co.uk/cmdow/

我编写了一个相当复杂的批处理文件,用于打开/重命名/重新定位 DOS 类型的命令窗口。每个 DOS 窗口都代表流式音频捕获实用程序的一个实例。

单个批处理文件会将“当前”(上次打开的)命令窗口重命名为带有时间戳的“旧”命令窗口名称。然后,它会将“旧”窗口重新定位到新的屏幕位置。然后,将启动一个新的“当前”命令窗口,并将其移动到现在的“旧”窗口先前占据的屏幕位置。

这样,我可以根据旧窗口的屏幕位置轻松识别旧窗口,以便手动关闭。如果多个“旧”窗口处于活动状态(多次运行批处理文件后),则所有“旧”窗口将堆叠在同一屏幕位置。如果批处理文件运行不正确,这也使我可以选择关闭“当前”窗口并让“旧”窗口保持活动状态。

虽然我将其用于命令窗口,但它也适用于任何其他窗口类型,包括浏览器窗口。上面的网页描述了 CMDOW 实用程序和“@”窗口标识符的众多控件。

下面是我的批处理文件的一小部分,它指定了环境变量和使用的 CMDOW 命令。为了避免可能出现的批处理问题,我将通用 cmdow 实用程序重命名为 cmdow.v1.4.3,以指示我正在使用的特定版本。cmdow 实用程序与批处理文件位于同一目录中(无需特殊安装 cmdow,只需运行该实用程序即可)。

REM --------------------------------
REM   SET THE BATCH CONTROL VARIABLES
set strInitialBatchWindow=STARTUP_INSTANCE_OF_stream-1(p)
set   strFinalBatchWindow=CURRENT_INSTANCE_OF_stream-1(p)
set   strBannerTextLine=Audio Stream  (for "Main" channel stream.)
set   strUsualRunPosition= 25 470
set   strRetirePosition= 25 270
set   strWindowSize=668 331
REM

  < Most of the batch setup details have been removed. >

REM move this window instance to it's final "Normal" runtime screen location.
cmdow.v1.4.3 @ /mov %strUsualRunPosition%
REM The following command resizes the current instance window.
cmdow.v1.4.3 @ /siz %strWindowSize%

相关内容