5

In Windows 10, I was able to use "Cascade Windows" with a simple .vbs script:

set objShell = CreateObject("shell.application")
call objShell.CascadeWindows()

The same is possible with PowerShell:

$ShellExp = New-Object -ComObject Shell.Application
$ShellExp.CascadeWindows()

However, in Windows 11, this is no longer possible. Nevertheless, the method is present in Windows 11. Issue the following PowerShell command:

New-Object -ComObject "Shell.Application" | gm | select Name, MemberType

And using e.g. AutoHotkey, I am able to "Cascade Windows" using the following script/command:

DllCall( "CascadeWindows", uInt,0, Int,4, Int,0, Int,0, Int,0 )

Is there a way to restore a functioning "Cascade Windows" action using VBScript or PowerShell?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Stijn Bousard
  • 331
  • 2
  • 8
  • Microsoft seems to have dropped quite a bit of the functionality from the contextual menu that's been there for decades (including this). You may have some luck reviewing the Win32 API page on the command (that's how AutoHotKey implements it): https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-cascadewindows. PowerShell would require it to be implemented in C#, at least (I don't really know what VBScript runs on). – TylerH Oct 22 '21 at 14:55

1 Answers1

2

Powershell (with embedded c#):

$code = @"
using System;
using System.Runtime.InteropServices;

namespace Utils
{
    public class CascadeWindowsApi
    {
        [DllImport("user32.dll")]
        static extern ushort CascadeWindows(IntPtr hwndParent, uint wHow,
        IntPtr lpRect, uint cKids, IntPtr[] lpKids);

        public static void Cascade()
        {
            CascadeWindows(IntPtr.Zero, 4, IntPtr.Zero, 0, null);
        }    
    }
}
"@

Add-Type -TypeDefinition $code -Language CSharp 
iex "[Utils.CascadeWindowsApi]::Cascade()"

Works on Windows 11.

Gerardo Grignoli
  • 14,058
  • 7
  • 57
  • 68
  • Nice, Gerardo. This way, I can use the CascadeWindows again without the need of a 3rd party tool (AutoHotkey) – Stijn Bousard Aug 23 '22 at 10:29
  • It does indeed cascade the windows. Though I have 8 desktops and it does it to all of them. Anyway to only have it affect the current desktop? – phazei Nov 15 '22 at 23:20