How to perform Win+D or Win+M with confidence? I mean, without using unreliable SendKeys and with return value. Nothing unusual, as there is the ‘Show desktop’ button.
Task: click on the ‘Show desktop’ button programmatically.
Requirements: use UIAutomation module to minimize all the windows without an exception.
Solution: there would be suggested a traditional way:
ipmo [path]\UIAutomation.dll; Get-UIADesktop | Get-UIAButton -Name 'Show desktop' | Invoke-UIAButtonClick;
Nope, this does not work even if we are running the PowerShell console window in the Minimized window state.
How can we fix the issue? Let’s use a Win32 click:
ipmo [path]\UIAutomation.dll; Get-UIADesktop | Get-UIAButton -Name 'Show desktop' | Invoke-UIAControlClick;
This code works as expected, from a minimized console, from a normal console, from everywhere.