Well, I am going to put this all on CodePlex tomorrow, but I promised a few people that I’d throw it up here for them yesterday, so I figured it’s past time to post it … without further ado. [new] The Window Automation Snapin and it’s source should be downloaded from the CodePlex project where updates can be tracked. :)

This is basically an upgrade to the Win32.Windows snapin I released a while back, the one thing that’s missing in this release that was possible in that one is using frame-set definitions to position windows. That will make it back in eventually, but in the meantime, I present some major new additions which add up to the ability to do 90% of what you’d want to do in testing or automating your winforms app’s UI.

  • Select-Window – pick windows by process name or window caption (with wildcard support)
  • Select-Control – pick controls by class and/or name and/or index (with wildcard support)
  • Send-Click – send mouse clicks (any button, with any modifier keys)
  • Send-Keys – Windows.Forms.SendKeys lets you send keys … try this: Select-Window notepad | Send-Keys "%(ea)Testing{Enter}{F5}" (and for extra fun, try it with multiple notepad windows open).
  • Set-WindowActive – yeah, just activates the window
  • Set-WindowPosition – set any one of (or all of) top, left, width, height on a window … or maximize/minimize/restore
  • Get-WindowPosition – get the position (kind-of redundant, actually, since the Window object has it’s position as a property)
  • Remove-Window – closes the specified window

There’s no help right now, so get used to using Get-Command -PSSnapin WindowAutomation and checking out the ParameterSets … hopefully you can figure it out from that for now. Oh, one other thing, there might be a few extras hiding in these:

  • [Huddled.Win32.WindowExtenders] | Get-Member -static
  • [Huddled.Win32.WindowFinder] | Get-Member -static

For now, that will have to do, it’s past time for bed. You might want to play with this and the out-voice script I posted on CodePlex awhile back, it makes things extra fun.