Tag Archives: RootElement

Daily automation: walking through the Start menu

Task: click the Computer item in the Start menu.

Requirements: use UIAutomation to demonstrate the technique.

Solution: although the solution is simple, it may be difficult to find out. The current version of UIAutomationSpy is slightly outdated and not yet recommends using the Get-UIADesktop cmdlet. Okay, this time we’ll do it manually, having in mind that a newer version of UIAutomationSpy is promised.

Here is the solution. At first, we open the Start menu by clicking the Start button. After that, we are seeking for a window that is the underlying level which the menu is placed upon. Finally, we get a list item, called of course Computer and send a Win32 click to there.

This sample is not ready to globalization.

ipmo [path]\UIAutomation.dll;

# click the Start button and open the Start menu
Get-UIADesktop | Get-UIAButton -Name Start | Invoke-UIAButtonClick; 
# Navigating through the Start menu and clicking the list item of our interest
Get-UIADesktop | Get-UIAcontrol -Class 'DV2ControlHost' -Name 'Start menu' | Get-UIAPane -Class 'DesktopSpecialFolders' | Get-UIAListItem -Name 'Computer' | Invoke-UIAControlClick;

After the code is processed by PowerShell, the Computer folder is open.


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.

Daily automation: open an application from the TaskBar

It’s easily to activate a window that is in the Normal or Maximized window state. However, what to do if a window is minimized? There’s no problem if it’s seen in the Windows TaskBar.

Task: click the window out of Windows TaskBar.

Requirements: use UIAutomation to demostrate the technique.

Solution: below is the piece of code that does the same the user does when one needs to return the window to a visible state. Apart with Alt+Tab and Alt+Shift+Tab, there is the simple click on the application’s rectangle in TaskBar.:

ipmo [path]\UIAutomation.dll;

# use the desktop element to get the button in TaskBar
# desktop AutomationElement is nothing else but
# [System.Windows.Automation.AutomationElement]::RootElement
Get-UIADesktop | Get-UIAButton -Name 'Windows Media Player' | Invoke-UIAButtonClick;

After the code is processed by PowerShell, the window of your choice appears on the screen.

%d bloggers like this: