Quick way to close all virtual desktops

Anonymous
2021-11-22T23:58:21+00:00

Is there a quick way to close all virtual desktops? I have close to 400 and it's very slow and time consuming to close each one.

The other posts similar to this didn't work, the Ctrl+windows+F4 didn't close unless I was in the Task View and then you have to open it again each time.

Thank you!

Windows Server Accessibility

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes
Accepted answer
  1. Anonymous
    2021-11-23T00:48:47+00:00

    Hi JonathanTodd6,

    Good day! This is Jhakesong and I will be happy to assist you with this.

    I am sorry to hear about the inconvenience. Give this power shell script a try and see if it suits your needs in closing the virtual desktops at once.

    Copy and paste this code in a notepad and save it as a .ps1 file and run it with powershell.

    Function CloseVirtualDesktopInWin10

    {

    $KeyShortcut = Add-Type -MemberDefinition @"
    
    [DllImport("user32.dll")]
    
    static extern void keybd\_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
    
    //WIN + CTRL + F4: Close the virtual desktop
    
    public static void CloseVirtualDesktopInWin10()
    
    {
    
        //Key down
    
        keybd\_event((byte)0x5B, 0, 0, UIntPtr.Zero); //Left Windows key 
    
        keybd\_event((byte)0x11, 0, 0, UIntPtr.Zero); //CTRL
    
        keybd\_event((byte)0x73, 0, 0, UIntPtr.Zero); //F4
    
        //Key up
    
        keybd\_event((byte)0x5B, 0, (uint)0x2, UIntPtr.Zero);
    
        keybd\_event((byte)0x11, 0, (uint)0x2, UIntPtr.Zero);
    
        keybd\_event((byte)0x73, 0, (uint)0x2, UIntPtr.Zero);
    
    }
    

    "@ -Name CloseVirtualDesktop -UsingNamespace System.Threading -PassThru

    $KeyShortcut::CloseVirtualDesktopInWin10()
    

    }

    Function CloseAllVirtualDesktopInWin10() {

    $maxNumber=1..800
    
    foreach ($n in $maxNumber)
    
    {
    
        CloseVirtualDesktopInWin10
    
    }
    

    }

    CloseAllVirtualDesktopInWin10

    Here is how to use it:

    https://www.addictivetips.com/windows-tips/clos...

    Reference:

    https://www.reddit.com/r/techsupport/comments/a...

    Note:

    1. Press Windows key + X, launch Windows Powershell Admin
    2. Paste this command and press enter:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

    1. Right click your .ps1 file and run it with Powershell.

    Let me know how it goes. Have a great day!

    ____________________________________________________________

    Standard Disclaimer: These are links to non-Microsoft websites. The pages appear to be providing accurate, safe information. Watch out for ads on the sites that may advertise products often classified as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the sites before you decide to download and install it. We strongly suggest not to install or purchase anything from the link.

    10 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-11-23T01:30:43+00:00

    That worked! Thank you so much!

    0 comments No comments