Freigeben über


Device Emulator and the Windows PowerShell

Was playing around with Windows PowerShell recently and it ROCKS. there has been a lot of coverage around PowerShell so I won't bore you with some of them, here's a great video screencast by Scott Hanselman to get your started on PowerShell.

What I wanted to do was to see how easily it would be for one to write a test harness for automating the instantiation of Device Emulators so that developers and testers can quickly test their application on different device configurations.

This sample uses the Managed Core Connectivity Wrappers that we've built into Visual Studio 2008 and the new Windows Mobile SDK.

You need the following installed before you can proceed:

  1. Windows Mobile 5.0 or 6 SDKs
  2. Windows PowerShell 1.0
  3. PowerTab Version 0.98

Here's how you can instantiate a device emulator from powershell.

Step 1: Start PowerShell in Administrator mode and enable script execution by typing "Set-ExecutionPolicy unrestricted", especially if you're on Vista.

powershell01

Step 2: Load the Microsoft.SmartDevice.Connectivity assembly using the LoadWithPartialName method.

powershell02

Step 3: Create the DataStoreManager object. "1033" is locale for "en-en"

powershell03

Step 4: Query the types of platforms that are installed on your machine. This will return the list of Windows Mobile Emulator platforms that were installed together with the SDK. If you have not installed the Windows Mobile 6 SDK, you won't see the Windows Mobile 6 Professional nor the Standard SDKs.

powershell04

Step 5: Enumerate Platforms and create a collection of platforms in $plat. Assign platform that you're interested in to $wm6, in this case we're using the Windows Mobile 6 Professional SDK. (item 0 in the collection)

powershell05

Step 6: Get the list of devices for that platform. This shows you all the possible device configurations / types that were installed with that platform.

powershell06

Step 7: Let's pick the Windows Mobile 6 Professional Emulator by picking device [1] and connect to the emulator using the $device.Connect() method.

powershell07

That's it :) pretty powerful. You can imagine how flexible PowerShell is by allowing you to write .NET Code together with Shell code to create automated scripts. You can now easily instantiate emulators and deploy custom configurations automatically to create a full automated test environment.

Comments

  • Anonymous
    September 26, 2007
    PingBack from http://www.artofbam.com/wordpress/?p=3185

  • Anonymous
    September 26, 2007
    PowerShell combined with CoreCon

  • Anonymous
    September 26, 2007
    The comment has been removed

  • Anonymous
    September 27, 2007
    Staffan, of course not, that would be best way to do it, but i'm using unrestricted in this demo to make life easier for me. :)

  • Anonymous
    September 29, 2007
    This looks great! So, do I need to have Visual Studio 2008 installed for the Managed Core Connectivity Wrappers or is the Windows Mobile 5 or 6 SDK enough? Having to install VS 2008 on my build server doesn't seem like a good idea. Thanks, Jeffry

  • Anonymous
    October 01, 2007
    The comment has been removed

  • Anonymous
    December 12, 2007
    Thanks to those of you that attended Reed and my presentation at the Windows Mobile Partner Summit .