PoshCode Logo PowerShell Code Repository

UIAutomation 1.6 by Joel Bennett 3 years ago (modification of post by Joel Bennett view diff)
View followups from Joel Bennett and Joel Bennett | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2483"></script>download | new post

The new WASP module is getting closer, but this still isn’t quite it ;)

  1. ## UI Automation v 1.6 -- REQUIRES the Reflection module (current version: http://poshcode.org/2480 )
  2. ##
  3. # WASP 2.0 is getting closer, but this is just a preview:
  4. # -- a lot of the commands have weird names still because they're being generated ignorantly
  5. # -- eg: Invoke-Toggle.Toggle and  Invoke-Invoke.Invoke
  6.  
  7.  
  8. #                                                                                                   #
  9. # Select-Window Notepad | Remove-Window -passthru                                                   #
  10. # ## And later ...                                                                                  #
  11. # Select-Window Notepad | Select-ChildWindow | Send-Keys "%N"                                       #
  12. # ## OR ##                                                                                          #
  13. # Select-Window Notepad | Select-ChildWindow |                                                      #
  14. #    Select-Control -title "Do&n't Save" -recurse | Send-Click                                      #
  15. #                                                                                                   #
  16.  
  17. #                                                                                                   #
  18. # PS notepad | Select-Window | Select-ChildWindow | %{ New-Object Huddled.Wasp.Window $_ }          #
  19. #                                                                                                   #
  20.  
  21.  
  22. # cp C:\Users\Joel\Projects\PowerShell\Wasp\trunk\WASP\bin\Debug\Wasp.dll .\Modules\WASP\           #
  23. # Import-Module WASP
  24.  
  25.  
  26. #PS1 [Reflection.Assembly]::Load()
  27. #PS1 [Reflection.Assembly]::Load()
  28.  
  29. Add-Type -AssemblyName "UIAutomationClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  30. Add-Type -AssemblyName "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  31.  
  32. $SWA = "System.Windows.Automation"
  33. #  Add-Accelerator InvokePattern      "$SWA.InvokePattern"                -EA SilentlyContinue
  34. #  Add-Accelerator ExpandPattern      "$SWA.ExpandCollapsePattern"        -EA SilentlyContinue
  35. #  Add-Accelerator WindowPattern      "$SWA.WindowPattern"                -EA SilentlyContinue
  36. #  Add-Accelerator TransformPattern   "$SWA.TransformPattern"             -EA SilentlyContinue
  37. #  Add-Accelerator ValuePattern       "$SWA.ValuePattern"                 -EA SilentlyContinue
  38. #  Add-Accelerator TextPattern        "$SWA.TextPattern"                  -EA SilentlyContinue
  39.  
  40. # This is what requires the Reflection module:
  41. Add-Accelerator Automation         "$SWA.Automation"                   -EA SilentlyContinue
  42. Add-Accelerator AutomationElement  "$SWA.AutomationElement"            -EA SilentlyContinue
  43. Add-Accelerator TextRange          "$SWA.Text.TextPatternRange"        -EA SilentlyContinue
  44. #####  Conditions
  45. Add-Accelerator Condition          "$SWA.Condition"                    -EA SilentlyContinue
  46. Add-Accelerator AndCondition       "$SWA.AndCondition"                 -EA SilentlyContinue
  47. Add-Accelerator OrCondition        "$SWA.OrCondition"                  -EA SilentlyContinue
  48. Add-Accelerator NotCondition       "$SWA.NotCondition"                 -EA SilentlyContinue
  49. Add-Accelerator PropertyCondition  "$SWA.PropertyCondition"            -EA SilentlyContinue
  50. #####  IDentifiers
  51. Add-Accelerator AutoElementIds     "$SWA.AutomationElementIdentifiers" -EA SilentlyContinue
  52. Add-Accelerator TransformIds       "$SWA.TransformPatternIdentifiers"  -EA SilentlyContinue
  53.  
  54. ##### Patterns:
  55. $patterns = Get-Type -Assembly UIAutomationClient -Base System.Windows.Automation.BasePattern
  56.             #| Where { $_ -ne [System.Windows.Automation.InvokePattern] }
  57.  
  58. Add-Type -TypeDefinition @"
  59. using System;
  60. using System.ComponentModel;
  61. using System.Management.Automation;
  62. using System.Reflection;
  63. using System.Text.RegularExpressions;
  64. using System.Windows.Automation;
  65.  
  66. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
  67. public class StaticFieldAttribute : ArgumentTransformationAttribute {
  68.   private Type _class;
  69.  
  70.   public override string ToString() {
  71.      return string.Format("[StaticField(OfClass='{0}')]", OfClass.FullName);
  72.   }
  73.  
  74.   public override Object Transform( EngineIntrinsics engineIntrinsics, Object inputData) {
  75.      if(inputData is string && !string.IsNullOrEmpty(inputData as string)) {
  76.         System.Reflection.FieldInfo field = _class.GetField(inputData as string, BindingFlags.Static | BindingFlags.Public);
  77.         if(field != null) {
  78.            return field.GetValue(null);
  79.         }
  80.      }
  81.      return inputData;
  82.   }
  83.  
  84.   public StaticFieldAttribute( Type ofClass ) {
  85.      OfClass = ofClass;
  86.   }
  87.  
  88.   public Type OfClass {
  89.      get { return _class; }
  90.      set { _class = value; }
  91.   }  
  92. }
  93.  
  94. public class UIAutomationHelper {
  95.   public static AutomationElement RootElement {
  96.      get { return AutomationElement.RootElement; }
  97.   }
  98. }
  99.  
  100. "@ -ReferencedAssemblies UIAutomationClient, UIAutomationTypes
  101.            
  102.            
  103.            
  104. ## TODO: Write Get-SupportedPatterns or rather ...
  105. ## Get-SupportedFunctions (to return the names of the functions for the supported patterns)
  106. ## TODO: Support all the "Properties" too
  107. ## TODO: Figure out why Notepad doesn't support SetValue
  108. ## TODO: Figure out where the menus support went
  109. ForEach($pattern in $patterns){
  110.    $pattern | Add-Accelerator
  111.    $PatternFullName = $pattern.FullName
  112.    $PatternName = $Pattern.Name -Replace "Pattern","."
  113.    $newline = "`n`t`t"
  114.    
  115.    New-Item "Function:Get-UIAPattern$($PatternName.TrimEnd('.'))" -Value "
  116.   param(
  117.      [Parameter(ValueFromPipeline=`$true)][Alias('Element','AutomationElement')][AutomationElement]`$InputObject
  118.   )
  119.   process {
  120.      trap { Write-Warning `"`$(`$_)`"; continue }
  121.      Write-Output `$InputObject.GetCurrentPattern([$PatternFullName]::Pattern).Current
  122.   }"
  123.    
  124.    $pattern.GetMethods() |
  125.    Where { $_.DeclaringType -eq $_.ReflectedType -and !$_.IsSpecialName } |
  126.    ForEach {
  127.       $FunctionName = "Function:Invoke-$PatternName$($_.Name)"
  128.       $Position = 1
  129.      
  130.       if (test-path $FunctionName) { remove-item $FunctionName }
  131.       $Parameters = @("$newline[Parameter(ValueFromPipeline=`$true)]"+
  132.                       "$newline[Alias('Parent','Element','Root','AutomationElement')]"+
  133.                       "$newline[AutomationElement]`$InputObject"
  134.                       ) +
  135.                     @(
  136.                       "[Parameter()]$newline[Switch]`$Passthru"
  137.                      ) +
  138.                     @($_.GetParameters() | % { "[Parameter(Position=$($Position; $Position++))]$newline[$($_.ParameterType.FullName)]`$$($_.Name)" })
  139.       $Parameters = $Parameters -Join "$newline,$newline"
  140.       $ParameterValues = '$' + (@($_.GetParameters() | Select-Object -Expand Name ) -Join ', $')
  141.  
  142.       $definition = @"
  143.   param(
  144.      $Parameters
  145.   )
  146.   process {
  147.      ## trap { Write-Warning "`$(`$_)"; break }
  148.      `$pattern = `$InputObject.GetCurrentPattern([$PatternFullName]::Pattern)
  149.      if(`$pattern) {
  150.         `$Pattern.$($_.Name)($(if($ParameterValues.Length -gt 1){ $ParameterValues }))
  151.      }
  152.      if(`$passthru) {
  153.         `$InputObject
  154.      }
  155.   }
  156. "@
  157.      
  158.       trap {
  159.          Write-Warning $_
  160.          Write-Host $definition -fore cyan
  161.       }
  162.       New-Item $FunctionName -value $definition
  163.    }
  164.    
  165.    $pattern.GetProperties() |
  166.    Where { $_.DeclaringType -eq $_.ReflectedType -and $_.Name -notmatch "Cached|Current"} |
  167.    ForEach {
  168.       $FunctionName = "Function:Get-$PatternName$($_.Name)".Trim('.')
  169.       if (test-path $FunctionName) { remove-item $FunctionName }
  170.       New-Item $FunctionName -value "
  171.      param(
  172.         [Parameter(ValueFromPipeline=`$true)]
  173.         [AutomationElement]`$AutomationElement
  174.      )      
  175.      process {
  176.         trap { Write-Warning `"$PatternFullName `$_`"; continue }
  177.         `$pattern = `$AutomationElement.GetCurrentPattern([$PatternFullName]::Pattern)
  178.         if(`$pattern) {
  179.            `$pattern.'$($_.Name)'
  180.         }
  181.      }"
  182.    }
  183.    ## So far this seems to be restricted to Text (DocumentRange) elements
  184.    $pattern.GetFields() |
  185.    Where { $_.DeclaringType -eq $_.ReflectedType -and $_.Name -like "*Attribute"} |
  186.    ForEach {
  187.       $FunctionName = "Function:Get-UIAAttribute$PatternName$($_.Name)"
  188.       if (test-path $FunctionName) { remove-item $FunctionName }
  189.       New-Item $FunctionName -value "
  190.      param(
  191.         [Parameter(ValueFromPipeline=`$true)]
  192.         [AutomationElement]`$AutomationElement
  193.      )
  194.      process {
  195.         trap { Write-Warning `"$PatternFullName `$_`"; continue }
  196.         `$AutomationElement.GetAttributeValue([$PatternFullName]::$($_.Name))
  197.      }"
  198.    }
  199.    
  200.    $pattern.GetFields() |
  201.    Where { $_.DeclaringType -eq $_.ReflectedType -and $_.Name -like "*Event"} |
  202.    ForEach {
  203.       $Name = $_.Name -replace 'Event$','Handler'
  204.       $FunctionName = "Function:Add-$PatternName$Name"
  205.       if (test-path $FunctionName) { remove-item $FunctionName }
  206.       New-Item $FunctionName -value "
  207.      param(
  208.         [Parameter(ValueFromPipeline=`$true)]
  209.         [AutomationElement]`$AutomationElement
  210.      ,
  211.         [System.Windows.Automation.TreeScope]`$TreeScope = 'Element'
  212.      ,
  213.         [ScriptBlock]`$EventHandler
  214.      )
  215.      process {
  216.         trap { Write-Warning `"$PatternFullName `$_`"; continue }
  217.         [Automation]::AddAutomationEventHandler( [$PatternFullName]::$Name, `$AutomationElement, `$TreeScope, `$EventHandler )
  218.      }"
  219.    }
  220. }
  221.  
  222. $FalseCondition = [Condition]::FalseCondition
  223. $TrueCondition  = [Condition]::TrueCondition
  224.  
  225. Add-Type -AssemblyName System.Windows.Forms
  226. Add-Accelerator SendKeys           System.Windows.Forms.SendKeys       -EA SilentlyContinue
  227.  
  228. $AutomationProperties = [system.windows.automation.automationelement+automationelementinformation].GetProperties()
  229.  
  230. Set-Alias Invoke-UIAElement Invoke-Invoke.Invoke
  231.  
  232. function formatter  { END {
  233.    $input | Format-Table @{l="Text";e={$_.Text.SubString(0,25)}}, ClassName, FrameworkId -Auto
  234. }}
  235.  
  236. function Set-UIAText {
  237. [CmdletBinding()]
  238. param(
  239.    [Parameter(Position=0)]
  240.    [string]$Text
  241. ,
  242.    [Parameter(ValueFromPipeline=$true)]
  243.    [Alias("Parent","Element","Root")]
  244.    [AutomationElement]$InputObject
  245. ,
  246.    [Parameter()]
  247.    [Switch]$Passthru  
  248. )
  249.    process {
  250.       if(!$InputObject.Current.IsEnabled)
  251.       {
  252.          Write-Warning "The Control is not enabled!"
  253.       }
  254.       if(!$InputObject.Current.IsKeyboardFocusable)
  255.       {
  256.          Write-Warning "The Control is not focusable!"
  257.       }
  258.      
  259.       $valuePattern = $null
  260.       if($InputObject.TryGetCurrentPattern([ValuePattern]::Pattern,[ref]$valuePattern)) {
  261.          Write-Verbose "Set via ValuePattern!"
  262.          $valuePattern.SetValue( $Text )
  263.       }
  264.       elseif($InputObject.Current.IsKeyboardFocusable)
  265.       {
  266.          $InputObject.SetFocus();
  267.          [SendKeys]::SendWait("^{HOME}");
  268.          [SendKeys]::SendWait("^+{END}");
  269.          [SendKeys]::SendWait("{DEL}");
  270.          [SendKeys]::SendWait( $Text )
  271.       }
  272.       if($passthru) {
  273.          $InputObject
  274.       }      
  275.    }
  276. }
  277.  
  278. function Set-UIAFocus {
  279. [CmdletBinding()]
  280. param(
  281.    [Parameter(ValueFromPipeline=$true)]
  282.    [Alias("Parent","Element","Root")]
  283.    [AutomationElement]$InputObject
  284. ,
  285.    [Parameter()]
  286.    [Switch]$Passthru  
  287. )
  288.    process {
  289.       $InputObject.SetFocus()
  290.       if($passthru) {
  291.          $InputObject
  292.       }        
  293.    }
  294. }
  295.  
  296. function Get-UIAClickablePoint {
  297. [CmdletBinding()]
  298. param(
  299.    [Parameter(ValueFromPipeline=$true)]
  300.    [Alias("Parent","Element","Root")]
  301.    [AutomationElement]$InputObject
  302. )
  303.    process {
  304.       $InputObject.GetClickablePoint()
  305.    }
  306. }
  307.  
  308. function Send-UIAKeys {
  309. [CmdletBinding()]
  310. param(
  311.    [Parameter(Position=0)]
  312.    [string]$Keys
  313. ,
  314.    [Parameter(ValueFromPipeline=$true)]
  315.    [Alias("Parent","Element","Root")]
  316.    [AutomationElement]$InputObject
  317. ,
  318.    [Parameter()]
  319.    [Switch]$Passthru
  320. ,
  321.    [Parameter()]
  322.    [Switch]$Async
  323. )
  324.    process {
  325.       if(!$InputObject.Current.IsEnabled)
  326.       {
  327.          Write-Warning "The Control is not enabled!"
  328.       }
  329.       if(!$InputObject.Current.IsKeyboardFocusable)
  330.       {
  331.          Write-Warning "The Control is not focusable!"
  332.       }
  333.          
  334.       $InputObject.SetFocus();
  335.      
  336.       if($Async) {
  337.          [SendKeys]::Send( $Keys )
  338.       } else {
  339.          [SendKeys]::SendWait( $Keys )
  340.       }
  341.      
  342.       if($passthru) {
  343.          $InputObject
  344.       }      
  345.    }
  346. }
  347.  
  348. function Select-UIElement {
  349. [CmdletBinding(DefaultParameterSetName="FromParent")]
  350. PARAM (
  351.    [Parameter(ParameterSetName="FromWindowHandle", Position="0", Mandatory=$true)]
  352.    [Alias("MainWindowHandle","hWnd","Handle")]
  353.    [IntPtr[]]$WindowHandle=[IntPtr]::Zero
  354. ,
  355.    [Parameter(ParameterSetName="FromPoint", Position="0", Mandatory=$true)]
  356.    [System.Windows.Point[]]$Point
  357. ,
  358.    [Parameter(ParameterSetName="FromParent", ValueFromPipeline=$true, Position=100)]
  359.    [System.Windows.Automation.AutomationElement]$Parent = [UIAutomationHelper]::RootElement
  360. ,
  361.    [Parameter(ParameterSetName="FromParent", Position="0")]
  362.    [Alias("WindowName")]
  363.    [String[]]$Name
  364. ,
  365.    [Parameter(ParameterSetName="FromParent", Position="1")]
  366.    [System.Windows.Automation.ControlType]
  367.    [StaticField(([System.Windows.Automation.ControlType]))]$ControlType
  368. ,
  369.    ## Removed "Id" alias to allow get-process | Select-Window pipeline to find just MainWindowHandle
  370.    [Parameter(ParameterSetName="FromParent", ValueFromPipelineByPropertyName=$true )]
  371.    [Alias("Id")]
  372.    [Int[]]$PID
  373. ,
  374.    [Parameter(ParameterSetName="FromParent")]
  375.    [String[]]$ProcessName
  376. ,
  377.    [Parameter(ParameterSetName="FromParent")]
  378.    [String[]]$ClassName
  379. ,
  380.    [switch]$Recurse
  381.  
  382. )
  383. process {
  384.  
  385.    Write-Debug "Parameters Found"
  386.    Write-Debug ($PSBoundParameters | Format-Table | Out-String)
  387.  
  388.    $search = "Children"
  389.    if($Recurse) { $search = "Descendants" }
  390.    
  391.    $condition = [System.Windows.Automation.Condition]::TrueCondition
  392.    
  393.    Write-Verbose $PSCmdlet.ParameterSetName
  394.    switch -regex ($PSCmdlet.ParameterSetName) {
  395.       "FromWindowHandle" {
  396.          $Element = $(
  397.             foreach($hWnd in $WindowHandle) {
  398.                [System.Windows.Automation.AutomationElement]::FromHandle( $hWnd )
  399.             }
  400.          )
  401.          continue
  402.       }
  403.       "FromPoint" {
  404.          $Element = $(
  405.             foreach($pt in $Point) {
  406.                [System.Windows.Automation.AutomationElement]::FromPoint( $pt )
  407.             }
  408.          )
  409.          continue
  410.       }
  411.       "FromParent" {
  412.          ## [System.Windows.Automation.Condition[]]$conditions = [System.Windows.Automation.Condition]::TrueCondition
  413.          [ScriptBlock[]]$filters = @()
  414.          if($PID) {
  415.             [System.Windows.Automation.Condition[]]$current += $(
  416.                foreach($p in $PID) {
  417.                   new-object System.Windows.Automation.PropertyCondition ([System.Windows.Automation.AutomationElement]::ProcessIdProperty), $p #.id
  418.                }
  419.             )
  420.             if($current.Length -gt 1) {
  421.                [System.Windows.Automation.Condition[]]$conditions += New-Object System.Windows.Automation.OrCondition $current
  422.             } elseif($current.Length -eq 1) {
  423.                [System.Windows.Automation.Condition[]]$conditions += $current[0]
  424.             }
  425.          }
  426.          if($ProcessName) {
  427.             if($ProcessName -match "\?|\*|\[") {
  428.                [ScriptBlock[]]$filters += { $(foreach($p in $ProcessName){ (Get-Process -id $_.GetCurrentPropertyValue([System.Windows.Automation.AutomationElement]::ProcessIdProperty)).ProcessName -like $p }) -contains $true }
  429.             } else {
  430.                [System.Windows.Automation.Condition[]]$current += $(
  431.                   foreach($p in Get-Process -Name $ProcessName) {
  432.                      new-object System.Windows.Automation.PropertyCondition ([System.Windows.Automation.AutomationElement]::ProcessIdProperty), $p.id
  433.                   }
  434.                )
  435.                if($current.Length -gt 1) {
  436.                   [System.Windows.Automation.Condition[]]$conditions += New-Object System.Windows.Automation.OrCondition $current
  437.                } elseif($current.Length -eq 1) {
  438.                   [System.Windows.Automation.Condition[]]$conditions += $current[0]
  439.                }              
  440.             }
  441.          }
  442.          if($Name) {
  443.             if($Name -match "\?|\*|\[") {
  444.                [ScriptBlock[]]$filters += { $(foreach($n in $Name){ $_.GetCurrentPropertyValue([System.Windows.Automation.AutomationElement]::NameProperty) -like $n }) -contains $true }
  445.             } else {
  446.                [System.Windows.Automation.Condition[]]$current += $(
  447.                   foreach($n in $Name){
  448.                      new-object System.Windows.Automation.PropertyCondition ([System.Windows.Automation.AutomationElement]::NameProperty), $n, "IgnoreCase"
  449.                   }
  450.                )
  451.                if($current.Length -gt 1) {
  452.                   [System.Windows.Automation.Condition[]]$conditions += New-Object System.Windows.Automation.OrCondition $current
  453.                } elseif($current.Length -eq 1) {
  454.                   [System.Windows.Automation.Condition[]]$conditions += $current[0]
  455.                }  
  456.             }
  457.          }
  458.          if($ClassName) {
  459.             if($ClassName -match "\?|\*|\[") {
  460.                [ScriptBlock[]]$filters += { $(foreach($c in $ClassName){ $_.GetCurrentPropertyValue([System.Windows.Automation.AutomationElement]::ClassNameProperty) -like $c }) -contains $true }
  461.             } else {
  462.                [System.Windows.Automation.Condition[]]$current += $(
  463.                   foreach($c in $ClassName){
  464.                      new-object System.Windows.Automation.PropertyCondition ([System.Windows.Automation.AutomationElement]::ClassNameProperty), $c, "IgnoreCase"
  465.                   }
  466.                )
  467.                if($current.Length -gt 1) {
  468.                   [System.Windows.Automation.Condition[]]$conditions += New-Object System.Windows.Automation.OrCondition $current
  469.                } elseif($current.Length -eq 1) {
  470.                   [System.Windows.Automation.Condition[]]$conditions += $current[0]
  471.                }                  
  472.             }
  473.          }
  474.          if($ControlType) {
  475.             if($ControlType -match "\?|\*|\[") {
  476.                [ScriptBlock[]]$filters += { $(foreach($c in $ControlType){ $_.GetCurrentPropertyValue([System.Windows.Automation.AutomationElement]::ControlTypeProperty) -like $c }) -contains $true }
  477.             } else {
  478.                [System.Windows.Automation.Condition[]]$current += $(
  479.                   foreach($c in $ControlType){
  480.                      new-object System.Windows.Automation.PropertyCondition ([System.Windows.Automation.AutomationElement]::ControlTypeProperty), $c
  481.                   }
  482.                )
  483.                if($current.Length -gt 1) {
  484.                   [System.Windows.Automation.Condition[]]$conditions += New-Object System.Windows.Automation.OrCondition $current
  485.                } elseif($current.Length -eq 1) {
  486.                   [System.Windows.Automation.Condition[]]$conditions += $current[0]
  487.                }                  
  488.             }
  489.          }
  490.          
  491.          if($conditions.Length -gt 1) {
  492.             [System.Windows.Automation.Condition]$condition = New-Object System.Windows.Automation.AndCondition $conditions
  493.          } elseif($conditions) {
  494.             [System.Windows.Automation.Condition]$condition = $conditions[0]
  495.          } else {
  496.             Write-Host "Oh no! It's the TRUE condition." -fore red
  497.             [System.Windows.Automation.Condition]$condition = [System.Windows.Automation.Condition]::TrueCondition
  498.          }
  499.          
  500.          if($filters.Count -gt 0) {
  501.             Write-Host "There are Filters too though ... " -fore red
  502.             $Element = $Parent.FindAll( $search, $condition ) | Where-Object { $item = $_;  foreach($f in $filters) { $item = $item | Where $f }; $item }
  503.          } else {
  504.             $Element = $Parent.FindAll( $search, $condition )
  505.          }
  506.       }  
  507.    }
  508.    
  509.    Write-Verbose "Element: $(@($Element).Count)"
  510.    if($Element) {
  511.       foreach($el in $Element) {
  512.          $e = New-Object PSObject $el
  513.          foreach($prop in $e.GetSupportedProperties() | Sort ProgrammaticName)
  514.          {
  515.             ## TODO: make sure all these show up: [System.Windows.Automation.AutomationElement] | gm -sta -type Property
  516.             $propName = [System.Windows.Automation.Automation]::PropertyName($prop)
  517.             Add-Member -InputObject $e -Type ScriptProperty -Name $propName -Value ([ScriptBlock]::Create( "`$this.GetCurrentPropertyValue( [System.Windows.Automation.AutomationProperty]::LookupById( $($prop.Id) ))" )) -EA 0
  518.          }
  519.          foreach($patt in $e.GetSupportedPatterns()| Sort ProgrammaticName)
  520.          {
  521.             Add-Member -InputObject $e -Type ScriptProperty -Name $patt.ProgrammaticName.Replace("PatternIdentifiers.Pattern","") -Value ([ScriptBlock]::Create( "`$this.GetCurrentPattern( [System.Windows.Automation.AutomationPattern]::LookupById( '$($patt.Id)' ) )" )) -EA 0
  522.          }
  523.          Write-Output $e
  524.       }
  525.    }
  526. }
  527.  
  528. }
  529.  
  530.  
  531.  
  532. #   [Cmdlet(VerbsCommon.Add, "UIAHandler")]
  533. #   public class AddUIAHandlerCommand : PSCmdlet
  534. #   {
  535. #      private AutomationElement _parent = AutomationElement.RootElement;
  536. #      private AutomationEvent _event = WindowPattern.WindowOpenedEvent;
  537. #      private TreeScope _scope = TreeScope.Children;
  538. #
  539. #      [Parameter(ValueFromPipeline = true)]
  540. #      [Alias("Parent", "Element", "Root")]
  541. #      public AutomationElement InputObject { set { _parent = value; } get { return _parent; } }
  542. #
  543. #      [Parameter()]
  544. #      public AutomationEvent Event { set { _event = value; } get { return _event; } }
  545. #
  546. #      [Parameter()]
  547. #      public AutomationEventHandler ScriptBlock { set; get; }
  548. #
  549. #      [Parameter()]
  550. #      public SwitchParameter Passthru { set; get; }
  551. #
  552. #      [Parameter()]
  553. #      public TreeScope Scope { set { _scope = value; } get { return _scope; } }
  554. #
  555. #      protected override void ProcessRecord()
  556. #      {
  557. #         Automation.AddAutomationEventHandler(Event, InputObject, Scope, ScriptBlock);
  558. #
  559. #         if (Passthru.ToBool())
  560. #         {
  561. #            WriteObject(InputObject);
  562. #         }
  563. #
  564. #         base.ProcessRecord();
  565. #      }
  566. #   }
  567.  
  568.  
  569. Export-ModuleMember -cmdlet * -Function * -Alias *
  570. # SIG # Begin signature block
  571. # MIIIDQYJKoZIhvcNAQcCoIIH/jCCB/oCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
  572. # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
  573. # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1J/dovQ2Sib/5ECSBjkJCtAP
  574. # TKmgggUrMIIFJzCCBA+gAwIBAgIQKQm90jYWUDdv7EgFkuELajANBgkqhkiG9w0B
  575. # AQUFADCBlTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0
  576. # IExha2UgQ2l0eTEeMBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYD
  577. # VQQLExhodHRwOi8vd3d3LnVzZXJ0cnVzdC5jb20xHTAbBgNVBAMTFFVUTi1VU0VS
  578. # Rmlyc3QtT2JqZWN0MB4XDTEwMDUxNDAwMDAwMFoXDTExMDUxNDIzNTk1OVowgZUx
  579. # CzAJBgNVBAYTAlVTMQ4wDAYDVQQRDAUwNjg1MDEUMBIGA1UECAwLQ29ubmVjdGlj
  580. # dXQxEDAOBgNVBAcMB05vcndhbGsxFjAUBgNVBAkMDTQ1IEdsb3ZlciBBdmUxGjAY
  581. # BgNVBAoMEVhlcm94IENvcnBvcmF0aW9uMRowGAYDVQQDDBFYZXJveCBDb3Jwb3Jh
  582. # dGlvbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMfUdxwiuWDb8zId
  583. # KuMg/jw0HndEcIsP5Mebw56t3+Rb5g4QGMBoa8a/N8EKbj3BnBQDJiY5Z2DGjf1P
  584. # n27g2shrDaNT1MygjYfLDntYzNKMJk4EjbBOlR5QBXPM0ODJDROg53yHcvVaXSMl
  585. # 498SBhXVSzPmgprBJ8FDL00o1IIAAhYUN3vNCKPBXsPETsKtnezfzBg7lOjzmljC
  586. # mEOoBGT1g2NrYTq3XqNo8UbbDR8KYq5G101Vl0jZEnLGdQFyh8EWpeEeksv7V+YD
  587. # /i/iXMSG8HiHY7vl+x8mtBCf0MYxd8u1IWif0kGgkaJeTCVwh1isMrjiUnpWX2NX
  588. # +3PeTmsCAwEAAaOCAW8wggFrMB8GA1UdIwQYMBaAFNrtZHQUnBQ8q92Zqb1bKE2L
  589. # PMnYMB0GA1UdDgQWBBTK0OAaUIi5wvnE8JonXlTXKWENvTAOBgNVHQ8BAf8EBAMC
  590. # B4AwDAYDVR0TAQH/BAIwADATBgNVHSUEDDAKBggrBgEFBQcDAzARBglghkgBhvhC
  591. # AQEEBAMCBBAwRgYDVR0gBD8wPTA7BgwrBgEEAbIxAQIBAwIwKzApBggrBgEFBQcC
  592. # ARYdaHR0cHM6Ly9zZWN1cmUuY29tb2RvLm5ldC9DUFMwQgYDVR0fBDswOTA3oDWg
  593. # M4YxaHR0cDovL2NybC51c2VydHJ1c3QuY29tL1VUTi1VU0VSRmlyc3QtT2JqZWN0
  594. # LmNybDA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmNv
  595. # bW9kb2NhLmNvbTAhBgNVHREEGjAYgRZKb2VsLkJlbm5ldHRAWGVyb3guY29tMA0G
  596. # CSqGSIb3DQEBBQUAA4IBAQAEss8yuj+rZvx2UFAgkz/DueB8gwqUTzFbw2prxqee
  597. # zdCEbnrsGQMNdPMJ6v9g36MRdvAOXqAYnf1RdjNp5L4NlUvEZkcvQUTF90Gh7OA4
  598. # rC4+BjH8BA++qTfg8fgNx0T+MnQuWrMcoLR5ttJaWOGpcppcptdWwMNJ0X6R2WY7
  599. # bBPwa/CdV0CIGRRjtASbGQEadlWoc1wOfR+d3rENDg5FPTAIdeRVIeA6a1ZYDCYb
  600. # 32UxoNGArb70TCpV/mTWeJhZmrPFoJvT+Lx8ttp1bH2/nq6BDAIvu0VGgKGxN4bA
  601. # T3WE6MuMS2fTc1F8PCGO3DAeA9Onks3Ufuy16RhHqeNcMYICTDCCAkgCAQEwgaow
  602. # gZUxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJVVDEXMBUGA1UEBxMOU2FsdCBMYWtl
  603. # IENpdHkxHjAcBgNVBAoTFVRoZSBVU0VSVFJVU1QgTmV0d29yazEhMB8GA1UECxMY
  604. # aHR0cDovL3d3dy51c2VydHJ1c3QuY29tMR0wGwYDVQQDExRVVE4tVVNFUkZpcnN0
  605. # LU9iamVjdAIQKQm90jYWUDdv7EgFkuELajAJBgUrDgMCGgUAoHgwGAYKKwYBBAGC
  606. # NwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgor
  607. # BgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQU4y8DgFgU
  608. # E4gFrdVXpPcBOvsvx+QwDQYJKoZIhvcNAQEBBQAEggEADdDsHJdQxMh9saVCbqer
  609. # SUk3ygs0LAiYF0IozBiHD1tY23CZokYGWAOCSfzF5gOJb9pa2p3oU8aH9PJWBSn7
  610. # HQ1x5RTPqccDUQA03ucgZAN0WQ/V27Zoahox1h8Q597zqp76y4T9bvBjv1lJju9P
  611. # 0tolEvS0uciAQhPgCvxbvRBdWmOKOK5TPSp6hEk3FsPPlgS9xp7twVNI4Kn619Ku
  612. # cKzoZQoTeFwefKuGMSWMVwKugw2ZJKRkTsoPSl4hDjZ2d5cZM+1bbaGOqxmSBeVr
  613. # wD3nfxZhZOGm54jbqu8WvObLB4znvGo1PBVi/vTb13ncdVFHBu10IQeW+STxLfpb
  614. # LQ==
  615. # SIG # End signature block

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me