C# 顯示桌面/所有視窗最小化

筆者找到了一個在 PowerShell 上 顯示桌面/所有視窗最小化 的指令:
    
(New-Object -ComObject Shell.Application).MinimizeAll()
    

在 C# 中可以這樣做:
    
            var shellType = Type.GetTypeFromProgID("Shell.Application");
            if (shellType != null)
            {
                dynamic? shell = Activator.CreateInstance(shellType);
                shell?.MinimizeAll();
            }
    

執行後就會顯示桌面了!

參考資料:
Microsoft.Learn - Shell.MinimizeAll method

留言