Feb 19 2010

Windows Phone Deployment Patterns Part 1 of n

Category: MobileJoel Ivory Johnson @ 15:47

One of the readers of this site contacted me via e-mail having read the first post in this series.  He wanted to know how to get one of the sharp looking icons in the start menu that you may have seen in Windows Mobile 6.5. We sent a few e-mails back and forth, identified a few obstacles, but got the icon on the start menu. The icons in the Windows Mobile 6.5 start menu are PNG files. You'll have to make a registry entry for your custom PNG icon to show up.  The registry location use is one that may be protected on devices with certain security settings. To ensure that an installation with a custom icon properly occurs the CAB will need to be signed. If you are distributing through the WindowsMarketplace for Mobile this will be done for you. Once security requirements are ment your CAB should have no problem registering the PNG. I'll cover two things in this post. (1) lowering the security requirements on your development device and (2) creating a deployment that will register the icon

Lowering the Security Requirements of your Development Device

There are two ways to lower/view the security settings on your device that I'll cover. One is using the Visual Studio Device Security Manager (Tools->Device Security Manager). If you are using a physical device connect it to your computer before you perform these steps. Once you start the Device Security Manager click on "Connect to Device" in it to select either the physical device connected to your computer or one of the emulators. After the the security tool connects select the "Security Off" profile and then click on "Deploy to Device" (I would love to discuss the meanings of the different profiles here but that strays to far from the set goal of this post).

The procedures for doing this with the Security Powertoy are pretty much the same. The one difference to note is that if you are running a 64-bit machine you'll find the Power Toy to be unusable unless you use the coreflags.exe tool.

What Needs to Occur for the Icon to Show?

By default Windows Mobile 6.5 will use your applications icon in the Windows Mobile 6.5 start menu. To use the PNG a registry entry needs to be made to associate your application's shortcut with the PNG file. The registry key must be created in [HKLM\Security\Shell\StartInfo\Start\MyShortCutName.lnk] where "MyShortCutName.lnk" is the name of the short cut icon for your application. You will need to create a new string key in this location named "Icon" that is set to the path to your PNG icon.

What do you need to do to make all of this happen? Start off with creating a deployment project as I described in part 0 of this series. In addition to the project output (executable) that you add to the deployment also add the PNG file for the icon you want to use. Right-click on the deployment project and select View->Registry to open the registry editor. The registry editor will show a series of folders representing the registry entries. Right-click on the HKEY_LOCAL_MACHINE folder and select "New Key." When prompted for the name of the key enter "Security". Continue to do this until you've created the full set of keys I've described above. After you create your "MyShortcutIcon.lnk" key you will need to create the string entry for it. Select your MyShortcutIconKey and then right-click in the pane to the right of the registry entried. Select New->String Value. Enter "Icon" for the name of the entry and "%InstallDir%\MyPngFileName.png" for the value (where MyPngFileName.png is the name of your PNG file).

If you compile your application and build your deployment you will have an installation that may or may not cause your custom icon to display. This is because of a race condition. The shortcut for the application is created before the registry entry is created. If the Sheel process happens to see the shortcut befor the registry entry is made then it will cache the shortcut icon instead of the PNG icon. If this happens your custom PNG icon will not show up until after the device resets. To avoid this problem you need to ensure that the registry entry is made before the shortcut icon is made. Unfortunatly there is no built-in support in Visual Studio to control the order of actions but all is not lost. To get around this problem I used a solution from Mike J. Francis. The solution that he provides consist of making an XML file that contains a set of install actions to create the shortcut icon instead of having the shortcut.lnk deployed through the file system editor.


Tags: , ,