Daily automation: show me the desktop


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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: