parameters - Specify monitor when opening file. (.bat) -


the following .bat file below opens 2 text files overlaying them, i'm wondering if it's possible define specific display source, or if can assist in providing correct parameters.

@echo off  start /max /wait notepad.exe c:\test\screen1.txt  start /max /wait notepad.exe c:\test\screen2.txt 

what i'm trying get:

@echo off  start /max /wait notepad.exe c:\test\screen1.txt "monitor1"   start /max /wait notepad.exe c:\test\screen2.txt "monitor2" 

so results trying receive screen1.txt opens on monitor1, , screen2.txt on monitor2.

unless application you're launching has command-line switch it, there's no easy way specify on monitor display window. far i'm aware, neither start nor notepad supports such switch. closest solution i've found move window after it's open.

and moving window no easy task, either. see this post other options. here's batch script compose , link c# app on fly handle window moves.

@echo off setlocal  :: // generate c.cs call :heredoc movewind >"%temp%\c.cs" && goto compile_and_link // syntax: movewind.exe [pid | "window title"] x y using system; using system.diagnostics; using system.runtime.interopservices;  class movewind {     [dllimport("user32.dll", setlasterror = true)]     private static extern bool setwindowpos(intptr hwnd, intptr hwndinsertafter, int x, int y, int cx, int cy, uint uflags);      [dllimport("user32.dll", setlasterror = true)]     static extern intptr findwindow(string lpclassname, string lpwindowname);      static void main(string[] args) {         int pid;         string title;         bool res = int32.tryparse(args[0], out pid);         if (res) {title = process.getprocessbyid(pid).mainwindowtitle;} else {title = args[0];}         intptr handle = findwindow(null, title);         try {             setwindowpos(handle, intptr.zero, convert.toint32(args[1]), convert.toint32(args[2]), 0, 0, 0x41);         }         catch (exception e) {             console.writeline("exception caught while attempting move window handle " + handle);             console.writeline(e);         }     } } :compile_and_link  set "movewind=%temp%\movewind.exe"  /f "delims=" %%i in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') (     if not exist "%movewind%" "%%i" /nologo /out:"%movewind%" "%temp%\c.cs" 2>nul ) del "%temp%\c.cs" if not exist "%movewind%" (     echo error: please install .net 2.0 or newer.     goto :eof )  :: // left monitor width /f "tokens=2 delims==" %%i in ('wmic desktopmonitor screenwidth /format:list') set "x=%%i"  :: // make sure test environment in place if not exist "c:\test" mkdir "c:\test" if not exist "c:\test\screen1.txt" >"c:\test\screen1.txt" echo should on left. if not exist "c:\test\screen2.txt" >"c:\test\screen2.txt" echo should on right.  :: // syntax: movewind.exe [pid | "window title"] x y start /max notepad.exe "c:\test\screen1.txt" call :movewind "screen1.txt - notepad" 0 0 start /max notepad.exe "c:\test\screen2.txt" call :movewind "screen2.txt - notepad" %x% 0  del "%movewind%"  :: // end main runtime goto :eof  :: // script functions  :movewind <title> <x> <y> tasklist /v | find /i "%~1" && (     "%movewind%" "%~1" %~2 %~3     goto :eof ) || (     ping -n 1 -w 500 169.254.1.1 >nul     goto movewind )  :heredoc <uniqueidx> :: // https://stackoverflow.com/a/15032476/1683264 setlocal enabledelayedexpansion set go= /f "delims=" %%a in ('findstr /n "^" "%~f0"') (     set "line=%%a" && set "line=!line:*:=!"     if defined go (if #!line:~1!==#!go::=! (goto :eof) else echo(!line!)     if "!line:~0,13!"=="call :heredoc" (         /f "tokens=3 delims=>^ " %%i in ("!line!") (             if #%%i==#%1 (                 /f "tokens=2 delims=&" %%i in ("!line!") (                     /f "tokens=2" %%x in ("%%i") set "go=%%x"                 )             )         )     ) ) goto :eof 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -