Store windows positions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Store windows positions

#1 Post by Matt Williamson » 27 Feb 2018 08:44

I'm not sure if this is possible or has been previously covered. I've done some searching but haven't found anything yet. I have multiple monitors at work. 2 24" and the display from my laptop. I use all 3 of them when I'm working but I have to take my laptop with me when I'm out in the field. When I do so, all of my windows go back to my laptop and when I plug it back in, I have to manually move all of my windows back. Is there any way I can store the locations so I can just run a script so they go back to the original positions? I'm running Windows 10 10.0.15063

Thanks,

Matt
Last edited by Matt Williamson on 27 Feb 2018 08:48, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Store windows positions

#2 Post by aGerman » 27 Feb 2018 11:51

That's not possible using Batch. I have a rough idea how to manage it using C and Windows API but I don't want to reinvent the wheel. Try to find an existing 3rd party. Most likely you're not the only one who wants to restore the window positions ...

Steffen

gustavo.lago
Posts: 4
Joined: 23 Feb 2018 08:52

Re: Store windows positions

#3 Post by gustavo.lago » 27 Feb 2018 11:53

I think that is not possible with DOS Batch.

Maybe this: https://github.com/adamsmith/WindowsLayoutSnapshot


Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Store windows positions

#5 Post by Matt Williamson » 27 Feb 2018 12:29

aGerman wrote:
27 Feb 2018 11:51
That's not possible using Batch. I have a rough idea how to manage it using C and Windows API but I don't want to reinvent the wheel. Try to find an existing 3rd party. Most likely you're not the only one who wants to restore the window positions ...

Steffen
Hi Steffan

Thanks for your reply. I looked pretty extensively before posting here and I didn't find any that work with this particular version of windows 10.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Store windows positions

#6 Post by Matt Williamson » 27 Feb 2018 12:30

gustavo.lago wrote:
27 Feb 2018 11:53
I think that is not possible with DOS Batch.

Maybe this: https://github.com/adamsmith/WindowsLayoutSnapshot
This doesn't work in Windows 10. I tested it and all of the forks. Thanks for your contribution though.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Store windows positions

#7 Post by Matt Williamson » 27 Feb 2018 12:31

I can't get to these from work. I'll have to take home an encrypted drive and grab them from home and hope they aren't blocked when I try to run them. Thanks for your contribution though.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Store windows positions

#8 Post by Squashman » 27 Feb 2018 12:56

Matt Williamson wrote:
27 Feb 2018 12:31
I can't get to these from work. I'll have to take home an encrypted drive and grab them from home and hope they aren't blocked when I try to run them. Thanks for your contribution though.
Yeah, that happens at my work as well. Majority of file sharing sites and others are blocked.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Store windows positions

#9 Post by Aacini » 27 Feb 2018 16:24

How the windows are manually moved back to the other monitors? I wonder if this could be done using my SendMessage.exe auxiliary program.

Antonio

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Store windows positions

#10 Post by aGerman » 27 Feb 2018 18:17

Maybe using WM_MOVE and WM_SIZE messages you could restore a window. But I'm not sure how to get those values using SendMessage.

If I had to write such a tool I would probably use EnumWindows to get the handles of all top-level windows. Then use GetWindowPlacement to get the neccessary data and save it for every window, maybe along with the window title or the window class name or even the process name it belongs to in order to be able to perform a proper comparison if the windows have to be restored. Restoring could be done using SetWindowPlacement. I have no clue if that would work with multiple monitors though.

Steffen

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Store windows positions

#11 Post by ShadowThief » 27 Feb 2018 20:23

I don't know about restoring positions, but I know that you can use powershell to access the Win32 API and set window positions to predefined sizes and locations.

jfl
Posts: 226
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

Re: Store windows positions

#12 Post by jfl » 06 Mar 2018 03:07

There's a PowerShell script called window.ps1 in my system management library for doing this.
There are many options. Run (window -?) or (help window -detailed) for details.
Example:

Code: Select all

PS C:\WINDOWS\system32> window | ft -a

    hWnd Program                  Left Top Width Height Title
    ---- -------                  ---- --- ----- ------ -----
 1247580 ApplicationFrameHost.exe  567 310  1061    801 Settings
11863656 chrome.exe                488  24  1348   1080 Store windows positions - DosTips.com - Google Chrome
 2951190 cmd.exe                   177  87   993    999 Administrator: Command Prompt
  197872 cmd.exe                    84  61   993    999 Administrator: Command Prompt
  787874 javaw.exe                 628   0  1282   1087 jEdit - FileW32.cpp
 1114136 notepad.exe               484 240  1176    967 t.bat - Notepad
  984636 notepad.exe               484 240  1176    967 Work log 2018-03-06.txt - Notepad
  983346 Notepad2.exe              405   8  1218   1080 Catalog.md - Notepad2
   66566 OUTLOOK.EXE                 0 554  1920    581 Inbox - jf.larvoire@hpe.com - Outlook
  723232 powershell.exe            400  30   993    999 Administrator: Windows PowerShell
  524344 SystemSettings.exe          0   0  1045    793 Settings
  263442 Explorer.EXE              486  48  1441   1044 Docs
  395230 Explorer.EXE              486  48  1441   1044 JFL
 1312270 javaw.exe                1078  42   504    493 Search And Replace
 1116284 Notepad2.exe              773 439   482    218 Find Text


PS C:\WINDOWS\system32> window "t.bat - Notepad" -MoveTo 200,80 -Resize 1200,1000 -OnTop
PS C:\WINDOWS\system32>

Post Reply