Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3309650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:39:58+00:00 2026-05-17T21:39:58+00:00

[I have posted this question earlier in the PowerShell Technet forum, but without a

  • 0

[I have posted this question earlier in the PowerShell Technet forum, but without a response]

I am attempting to change Windows XP Quick Launch settings (enable / disable it using PowerShell). Existing VBScript solutions rely either on Registry or SendKeys, so I thought that this would be feasible in PowerShell through UIAutomation. My first attempt was just to get the reference to the AutomationElement that represents the check box that needs to be changed (Control Panel -> Taskbar and Start Menu -> Taskbar tab -> Show Quick Launch check box). Here is the script:

[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClient")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationTypes")

$root = [Windows.Automation.AutomationElement]::RootElement

$condition1 = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, 'Taskbar and Start Menu Properties')
$properties = $root.FindFirst([Windows.Automation.TreeScope]::Descendants, $condition1)

$condition2 = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, 'Show Quick Launch')

$checkboxes = $properties.FindAll([Windows.Automation.TreeScope]::Descendants, $condition2)

foreach($checkbox in $checkboxes)
{
  $checkbox.Current.Name
  $checkbox.Current.ControlType.ProgrammaticName
}

The scripts doesn’t error out, but it returns unexpected results:

Show Quick Launch

ControlType.Pane

Instead of ControlType.CheckBox the script sees the AutomationElement as ControlType.Pane. The equivalent (at least I think so) C# console application returns the expected results:

using System;
using System.Windows.Automation;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
      AutomationElement root = AutomationElement.RootElement;
      AutomationElement properties = root.FindFirst(
        TreeScope.Descendants,
        new PropertyCondition(AutomationElement.NameProperty,
          "Taskbar and Start Menu Properties"));

      AutomationElementCollection checkboxes = properties.FindAll(
        TreeScope.Descendants,
        new PropertyCondition(AutomationElement.NameProperty,
          "Show Quick Launch"));

      foreach (AutomationElement checkbox in checkboxes)
      {
        Console.WriteLine(checkbox.Current.Name);
        Console.WriteLine(checkbox.Current.ControlType.ProgrammaticName);
      }
    }
  }
}

Show Quick Launch

ControlType.CheckBox

What am I doing wrong? The PowerShell script is executed from the ISE (so V2) and both the script and the C# program assume that the applet is already open / visible. (XP SP3)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:39:59+00:00Added an answer on May 17, 2026 at 9:39 pm

    Based on Using WPF UI Automation with PowerShell (CodeProject) and Problem finding AutomationElement in PowerShell script (MSDN Forums):

    1. UI Automation API works only from STA threads and PowerShell always runs scripts MTA. The workaround for this is to run PowerShell with the -sta switch or to run scripts from within the PowerShell ‘Integrated Scripting Environment’ (ISE) which defaults to STA.

    2. PowerShell handles value types problematically. The solution is to insert some inline C# code in the script to get the UIAutomation root element.

    Working code:

    [void] [Reflection.Assembly]::Load('UIAutomationClient, ' + 
        'Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
    [void] [Reflection.Assembly]::Load('UIAutomationTypes, ' + 
        'Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
    $source = @"
    using System;
    using System.Windows.Automation;
    namespace UIAutTools
    {
        public class Element
        {
            public static AutomationElement RootElement
            {
                get
                {
                    return AutomationElement.RootElement;
                }
            }
        }
    }
    "@
    Add-Type -TypeDefinition $source -ReferencedAssemblies( `
        "UIAutomationClient", "UIAutomationTypes")
    $root = [UIAutTools.Element]::RootElement
    $condition = New-Object Windows.Automation.PropertyCondition( `
        [Windows.Automation.AutomationElement]::NameProperty, `
        'start')
    $startButton = $root.FindFirst( `
        [Windows.Automation.TreeScope]::Descendants, $condition)
    $startButton.Current.Name
    $startButton.Current.ControlType.ProgrammaticName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about this question . I posted a reply there but
(This is technically an addendum to an earlier StackOverflow question I had posted, but
Haven't seen many Geneva related questions yet, I have posted this question in the
I've posted this on django-users but haven't received a reply! So I have my
I have posted this question on the Ext-GWT forums, I am just hoping that
What are extension methods in .NET? EDIT: I have posted a follow up question
I have already posted something similar here but I would like to ask the
I posted a question earlier today when I'd not zeroed in quite so far
I ask because my buddy posted a question earlier on How to resolve issue
I'm working from a question I posted earlier ( here ), and trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.