PowerShell In GUI Blog

PowerShell GUI Box Just In A Few Clicks

Tip of the day: using wildcards in UIAutomation

leave a comment »

One of amazing features of PowerShell cmdlets is supporting so-called wildcards. What are wildcards? The characters that substitute one or more, or even all of the characters in the string.
For example, you need to simplify your code:

Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -Name a* | Invoke-UIAButtonClick;

This code presses the plus button, the button that is named Add.
Imagine that you need to press the Reciprocal button and you’ll immediately love wildcards.

Written by Alexander Petrovskiy

August 26, 2012 at 9:17 am

Posted in Powershell, tip

Tagged with

Metro automation: getting started

leave a comment »

After a long hiatus, yesterday, I suddenly thought that it’s the time to return to Metro automation. To my surprise, rumors have been already circulating that Windows 8 Next Preview is upcoming in hours. Intuition? Maybe. In time is in time.

Yesterday I added to UIAutomaitonSpy the functionality to run PowerShell scripts. Today I polished a bit (here is great volume of work to do).

Let’s start. I tested the following on Windows 8 CP x64 and Windows 8 RP x86 (Release Preview of June, 01st). The binaries was built on a Windows 8 CP x64 box.ImageC

1. download the package. It’s not the default release now.

2. Unpack the package to a certain directory. We need to put in a secure location. One of them is %SystemRoot%, the other is %ProgramFiles%. The latter is more appropriate. In my tests, I creates the “C:\Program Files\1” directory and put the binaries there. You have in the folder UIAutomationSpy.exe, the config, UIAutomation.dll and TMX.dll.


3. One more file you’ve got is a certificate. You need to install it. Alternatively, you can sign UIAutomationSpy.exe with the certificate you possibly have.

Otherwise, below are screenshots. Run certmgr, for example, from cmd.exe and follow the pictures:








After you installed the certificate and the application in the secure location (you might set the policy not to require this if you’d like to), you can run the application.

For the first test, just run the application, agree with UAC and manually run the Start screen by pressing the Win button. Now you should see something like on the picture below:


On the picture, UIAutomationSpy shows the code for the Mail tile. It is bordered with the red rectangle. All that I’d like to offer is to explore tiles:


This is a text box, Edit in terms of UIAutomation.

Tomorrow I’m planning to start discussing how to write and run scripts for Metro UI.



Written by Alexander Petrovskiy

June 1, 2012 at 10:05 pm

Posted in Powershell

Tagged with , ,

W8: if Task Manager had previews…

with 2 comments

I just wondering why Task Manager is deprived of icon pop-ups that apllications in TaskBar have.

Written by Alexander Petrovskiy

March 5, 2012 at 8:59 pm

Posted in Powershell

The UIAutomation module is out

leave a comment »

The blog that specializes in software testing using PowerShell has published an announcement about the release of a new module, the UIAutomation module.

Along with the WASP module, this one is the only native PowerShell tool for testing. Tools like white, watir or MS TestAPi are not very easy to implement in your PowerShell scripts. At least, you need to create wrappers, what is the additional and not ever needed work.

Instead, native PowerShell modules are intended to be used within script, fully support pipelining (not interchangeble with each other so) and make life of PowerShell warrior a bit easier.

I happened to be one of a small team of early adopters of the UIAutomation module, and need to say that the module works almost well (and definitely the thing that is good for its $0).

The download link: http://uiautomation.codeplex.com/releases/view/82076#DownloadId=340717

Written by Alexander Petrovskiy

February 12, 2012 at 11:03 am

PowerShell Wizard. Round 2. It works!

with one comment

After posting the wizard sample, I thought – why don’t finish it today? I added

  • the Finish and the Cancel buttons in a way that the Finish button asks the user whether one wishes to exit now or not. The Cancel is available on the first step and by clicking this the user quits immediately
  • scriptblocks, used as a code that is run on clicking the Next button
  • fixed bugs, added comments here and there and a bit of polishing

At first, I’d like to show what the sample does.

It starts the wizard, sets the second step as the first the user sees (just for example) and provides a label saying that the wizard is awaiting for a path to any directory.

After that the user presses the next button (it stays here if the text box field is empty. The wrong path won’t be accepted too) and goes to the next step called, just for example, the Progress step:

The step called in the sample as Output contains a list box filled with the files list:

After all, at the last step can be written something encouradging, or an error log to be shown, or something else. There comes the Finish button, as well as the Cancel button comes at the first step of the wizard:

Now, after we know what this does, I can post the code running the sample:

		# Step 1: Welcome
		New-WizardStep 'Welcome' `
			'This is the first step' `
			'Welcome to the PowerShell Wizard, the our dear customer!';
		# Add a label
		# Please note that we can use the enumeration $steps which is being created runtime
		# on a call of the New-WizardStep function
		Add-ControlToStep $steps.Welcome `
			System.Windows.Forms.Label `
			'lblWelcome' 20 10 50 300 `
			'This Wizard carries you through the steps you need to collect the files from a given path';

		# Step 2
		New-WizardStep 'Input' `
			'Step Two' `
			'Here you type some in controls, plz';
		# Add a label
		Add-ControlToStep $steps.Input `
			System.Windows.Forms.Label `
			'lblInput' 20 10 20 300 `
			'Please type the path to a catalog';
		# Add a text box
		Add-ControlToStep $steps.Input `
			System.Windows.Forms.TextBox `
			'txtInput' 40 10 20 300
		# Add the code which requires that text box was not empty
		Add-CodeToStep $steps.Input `
			-StepCode {
					[string]$private:path = `
					if ($private:path.Length -eq 0)
						# stop the step
					if (-not [System.IO.Directory]::Exists($private:path))
						# stop the step

		# Step 3
		New-WizardStep 'Progress' `
			'The third one' `
			'Wait, please. Sip a coffee' ;
		# Add a progress bar
		Add-ControlToStep $steps.Progress `
			'System.Windows.Forms.ProgressBar' `
			'pbDir' 200 50 100 400
		Add-CodeToStep $steps.Progress `
			-StepCode {
					# set progress bar maximum
					$wzdSteps[$steps.Progress].Controls['pbDir'].Minimum = 0;
					$wzdSteps[$steps.Progress].Controls['pbDir'].Value = 0;
					$wzdSteps[$steps.Progress].Controls['pbDir'].Maximum = `
						(Get-ChildItem $wzdSteps[$steps.Input].Controls['txtInput'].Text).Length;
					# clear the list box (from the next step)
					# add file names to the list box
					Get-ChildItem $wzdSteps[$steps.Input].Controls['txtInput'].Text | %{

		# Step 4
		New-WizardStep 'Output' 'Fourth' `
			'Now awake and read the output';
		# Add a list box
		Add-ControlToStep $steps.Output `
			System.Windows.Forms.ListBox `
			lbxFiles 50 50 300 400

		# Step 5: Finish
        New-WizardStep 'Finish' 'Finish!' 'Bye!';

		# Set the second step as active
		Invoke-WizardStep -Forward $true;

		$script:frmWizard.ShowDialog() | Out-Null;

The full version is posted in the box at rigth and published on the PoshCode. Ask for a doc or more comments in the code if you need to.

Kindle for PowerShellers. Part 3. Reading your favorite blogs. Instapaper

leave a comment »

In the previous post of this series, we tested Amazon’s blog subscription. Now we must review an alternative solution, because it’s so common in the modern world to have free and/or open source counterparts of almost every application. I’d like to announce the Instapaper service review!

At first, let’s look at their version of how to publish blogs. The Contents is, in my opinion, better than the one Amazon compiles (but contents list of newspapers and magazines I like the most):

The View Articles List layout is exactly the very layout in Amazon’s subscriptions:

The following pictures display the article itself, the same one we tested earlier:

No pictures is added to an article, thus I’ll give only one screenshot to help you comprehend how much and, at the same time, how infinitesimal the difference between paid and free solutions.

The paid solution provides pictures, but the free one provides the better contents list. One thing to finish this comparison is to go the same way the user must go every time one wishes to download a new issue.

After registration on the Instapaper page, the registration is free, but you are given the possibility to pay $1 a month to support the project, you might begin collecting your articles list. Mine, used as an example for the subscription shown above, is today as follows:

The figure shows several noticeable things:

  • The ‘Add folders’ link to make the Contents of your issue organized in a manner you’d prefer
  • The ‘Read Later’ bookmarklet, the mechanism which you will use to gather pages you want to have in the issue
  • The Download options, where the central of them allows you to compile the issue right now and download it to a computer, whence you may sent it to a Kindle through wire or air.

I rarely use the first bullet owing to the perpetual lack of time, so that let’s immediately discuss the second one. After installing the bookmarklet, all the work you need to perform is to navigate to a page you want to add and to click the button. A monotonous, but not a very long and Amazon’s paiments-free task.

When your collection is replete with articles and you are ready to compile the issue (automated compilation and sending to a Kindle never worked for me), it’s about time to visit the ‘Account Settings’ section:

By clicking on the ‘Manage my Kindle settings’ link, you are in the very heart of your subscription:

Here you may set delivery settings and the address of your Kindle. Don’t forget to click on the ‘Save changes’ button. Also, here is one of the most interesting features of this service, the ‘Send now’ button, the button I used to demonstrate the issue.

Written by Alexander Petrovskiy

May 26, 2011 at 10:11 pm

Kindle for PowerShellers. Part 2. Reading your favorite blogs. The Amazon’s way

with one comment

The Kindle gives great possibilities to read blogs you accustomed to follow. The first way to do that is what Amazon offers – the blog subscription. The number of blogs you may choose to subscribe is significant, so that there are ratings, categorizing  and search helping you.

By today, the extent of quality of pictures and the usability of reading long lines of text and code are not what all the users agree to accept. Therefore, the two weeks’ trial is the time you may decide whether you need or needn’t to subscribe. No more restrictions here, even hundreds of blogs can be tested for two weeks.

To see what does a PowerShell blog on a Kindle  like, let’s take one of officials blogs, the PowerShell Guy blog. Below is today’s article:

As can be seen, pictures are now allowed in blogs as well as in newspapers (only several months ago pictures were almost prohibited here and there, in newspapers). Unfortunately, pictures are not of perfect quality due to the promise to deliver a blog in sixty seconds including the transmitting over 3G networks. On the other hand, technical blogs are not for seeing photos.

Amazon provides two options to see more on pictures: to increase on a click

and to visit the source by clicking on the small icon at the right side of a picture.

Articles are collected to a something like a newspaper (newspapers I like more because of their Contents style):

Even with the smallest available font size the contents is worse, to my mind, than those in a newspaper:

The contents in a newspaper or in a magazin is always of one page, whilst for the blog we took we see seven pages, what is sometimes even more than in some books of a thousand pages.

Owing to the discrepancy between text rendering in an HTML page and the Kindle screen, text and code are readable, but even with the smallest font the lines are longer than the width of a Kindle screen:

To conclude this review (and to turn to a review of alternative ways to read blogs), there’s time to say that you are usually charged to pay for this service from $0.99 to $1.99 a month. So that it’s your clue to choose blogs that to be updated daily or weekly, the more the blog is informative, the more often it gets updated, the more money Amazon ask for reading it.

Written by Alexander Petrovskiy

May 26, 2011 at 10:01 am