Search code examples
windowsbatch-filecmdvlc

Assigning window handles to variables in cmd to script moving windows around


I'm using VLC's clone feature to display the same video on extended displays using the same controls. These windows are borderless, so I cannot move them around using a mouse. Per default, VLC opens them on the main display on top of each other.

I want to write a script that moves those windows to different coordinates.

I've tried using cmdow.exe to move open windows around. However, I need to address them individually. The only difference is their Handle. My output looks like this:

C:\cmdow.exe "VLC (Direct3D9 output)"
Handle  Lev  Pid -Window status- Image   Caption
0x1E084A 1 17740 Res Ina Ena Vis vlc     VLC (Direct3D9 output)
0x170762 1 17740 Res Ina Ena Vis vlc     VLC (Direct3D9 output)

Of course, the Handle values will change every time VLC is reopened.

How do I assign these values to variables in a script?


Solution

  • Seeing as you want to set variables (which is not needed) you would never know the amount of lines returned, we can therefore create an array of variables with values:

    @echo off
    setlocal enabledelayedexpansion
    set cnt=0
    for /f "skip=1" %%i in ('cmdow.exe "VLC (Direct3D9 output)"') do (
       set /a cnt+=1
       set handle!cnt!=%%i
    )
    for /l %%a in (1,1,%cnt%) do echo !handle%%a!
    

    The for /l loop will simply be able to allow you to use each variable set, whether 1 or 1000