Windows has virtual desktops which is great. I use separate desktops for different things I am working on. But if I close a program (or reboot), then when I open the program again the program appear on the desktop I am currently on. So I manually have to move the program back.

I guess for chrome it is even more complicated as it is the same program with different windows. It would be nice to have the windows stay on the desktop they were before closing.

Similar to these issues with the difference of my question asking to remember windows position as opposed to setting it explicitly.

  • In order to achieve your workflow you would need to use a third-party utility to manage your application instances (i.e. windows). What you want is not possible with the built-in Virtual Desktop feature. – Ramhound Aug 27 '19 at 19:54
  • OK. But is there a program that can do it? I.e. remember last position across virtual desktops and hopefully somehow also work when multiple instances (e.g. chrome) are used. – Jan Stanstrup Aug 27 '19 at 20:06
  • There were virtual desktops thanks to third-party developers long before it was introduced in Windows 10. However, if they function exactly how you want, I couldn't say one way or another. I am also unable to provide any specific recommendations for obvious reasons. – Ramhound Aug 27 '19 at 20:19
  • How can the windows be identified? Do they have the same title when relaunched after the boot? – harrymc Aug 29 '19 at 12:21
  • Chrome seems to use the same name for all windows so I don't think that can be done. In chrome.google.com/webstore/detail/tabs-outliner/… you can assign names but I think they are internal to the extension. – Jan Stanstrup Aug 30 '19 at 10:24

This can be done with the below AutoHotKey script, which accepts two shortcut keys:

  • F11 : Will write the titles of all current windows and their virtual desktop numbers to a text file specified in the parameter FILENAME that is found at the beginning of the script.
  • F12 : Reads the text file and moves all the windows it can find by their title to the specified virtual desktop.

Copy the following text into an .ahk file, possibly changing "FILENAME", "F11" and "F12". Double-click the file to start it executing. It will create a green "H" icon in the traybar that you can right-click and select Exit to stop. If you always want this script to execute, copy it to the user Startup folder at C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

This script requires to download from the Github project windows-desktop-switcher the DLL VirtualDesktopAccessor.dll and storing it in the same folder as the AutoHotKey script. It might not work for Windows 10 versions below 1809.

The script itself is below and is programmed for only one monitor. It does not create the virtual desktops, so they should be created before running it. It worked for me, but should be tested. As it's using undocumented features, it might stop working some time in the future.

DetectHiddenWindows Off
SetTitleMatchMode, 2

FILENAME = C:\Temp\possaves.txt

hVirtualDesktopAccessor := DllCall("LoadLibrary", Str, "VirtualDesktopAccessor.dll", "Ptr") 
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr")
IsWindowOnDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsWindowOnDesktopNumber", "Ptr")

global numdesktops := GetDesktopsNumber()

F11::  ; Write list of "desktop@title"
EnumAddress := RegisterCallback("EnumWindowsProc", "Fast")
global numwins := 0
global file := FileOpen(FILENAME, "w")
DllCall("EnumWindows", "Ptr", EnumAddress, "Ptr", 0)

F12::  ; Read list and execute
global result
Loop, Read, %FILENAME%
    word_array := StrSplit(A_LoopReadLine, "@",, 2)  ; Omits periods.
    hwnd := WinExist(word_array[2])
    if (hwnd)
        DllCall(MoveWindowToDesktopNumberProc, UInt, hwnd, UInt, word_array[1] - 1)

    RegRead, cur, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\1\VirtualDesktops, CurrentVirtualDesktop
    RegRead, alldesktops, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs
    return floor(strlen(alldesktops) / strlen(cur))

EnumWindowsProc(hwnd, lParam)
    WinGetTitle, title, ahk_id %hwnd%
    if title {
        desktopnum := GetHWNDDesktopNumber(hwnd)
        if (desktopnum >= 0) {
            numwins := numwins + 1
            line = % desktopnum "@" title "`r`n"
    return true

  global  numdesktops, IsWindowOnDesktopNumberProc
  Loop, %numdesktops% {
    ix := A_Index - 1
    windowIsOnDesktop := DllCall(IsWindowOnDesktopNumberProc, UInt, hwnd, UInt, ix)
    if (windowIsOnDesktop == 1)
      return A_Index
  return -1
  • Will this work with chrome? I imagine all window titles will be the same? – Jan Stanstrup Sep 2 '19 at 8:45
  • The Chrome window title contains the website's title, so titles of Chrome windows for different websites are not the same. – harrymc Sep 2 '19 at 8:49
  • Have you tried the script? – harrymc Sep 3 '19 at 19:38
  • Not yet. I will get around to it this weekend I hope. I am sorry but it seems I screwed up with the bounty by being to slow. – Jan Stanstrup Sep 5 '19 at 12:48
  • Yes you did do that. – harrymc Sep 5 '19 at 14:02

I tried harrymc's solution and it worked fine on a Win10 64-bits, v1903. The solution allows to record multiple Chrome windows running in different virtual desktops (Fn+F11). If all Chrome windows appear in the same virtual desktop after reboot, using (Fn+F12) sends each Chrome window to the recorded virtual desktop.

I tried with 50 Chrome windows distributed over 10 virtual desktops. It took 2-3 seconds to generate the file.

@harrymc: Thank you very much! For some reason I need to press Fn+F11 or Fn+F12 in my laptop. The F11 and F12 keys alone do not trigger the functions of the AutoHotKey script.


There's currently no way to configure plain Windows like that but this issue can be solved by using third-party lightweight utility called VDesk (https://github.com/eksime/VDesk). It allows you to create shortcuts that will start programs on specific virtual desktops.

It also allows to start programs on different virtual desktop without switching to it (in fact running that app hidden until you manually switch to that desktop) which is very handy feature.

Specifically for Chrome you can create different Windows on different desktops by creating shortcuts looking like this (and then just clicking them):

vdesk on:3 run:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" /new-window "https://superuser.com"

(above will run superuser.com on desktop #3)

  • Yes I saw this elsewhere too. But it would require you to pre-define websites. It is not very handy for keeping active work organized where you will open lots of different pages. – Jan Stanstrup Sep 2 '19 at 8:45
  • You don't have to pre-define websites. If you want 3 desktops - one for Work, one for School and one for Fun you still can pre-open one generic empty Chrome Window on each of them. For example, I use VDesk to setup my workflows. On desktop I use for code reviews it opens Chrome Window and Terminal, while on desktop I use for coding it opens my editor, debugger and also Chrome. – blami Sep 4 '19 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.