Search code examples
windowsuser-interfacevbscriptwindow

How to get/set each applications window position and size in VBScript?


I'd like to write a script to organize the windows I currently have open on my screen.

Ex: Move all browsers to monitor 1 and everything else to monitor 2 Ex: Make the 4 maximized windows on monitor 1 each take up equal sized quadrants on the screen etc..

I assume VBScript would be good for this? What Objects would I use for this in a Win7 environment?


Solution

  • This isn't possible in VBScript out-of-the-box, because it doesn't provide access to Windows APIs used for window management.

    AutoIt seems a better tool for the job. Look into the following functions and macros:

    • WinMove - move windows
    • _WinAPI_GetSystemMetrics(80) - get the number of monitors
    • @DesktopWidth and @DesktopHeight - primary monitor pixel size
    • _WinAPI_GetSystemMetrics(78) and _WinAPI_GetSystemMetrics(79) - full desktop width and heigth

    If the monitor dimensions are different, you can use the WMI class Win32_DesktopMonitor and its ScreenWidth and ScreenHeigth properties to get individual monitor dimensions.