Create Setup Files for your Windows Mobile Applications Using Visual Studio 2005

isual Studio 2005 has great support for building Windows Mobile applications such as Pocket PC and Smartphone applications. But what happens after an application is completed and ready to be deployed onto the user’s device? In Visual Studio 2005, deploying an application to a device is simply a matter of connecting that device to the development machine using ActiveSync and then pressing the F5 key. However, this method of deployment is not acceptable to end users. End users are accustomed to GUI setup applications that hide the details of the installation process.

In this article, you will learn how to build CAB files for your Windows Mobile applications so that they can be deployed to your Windows Mobile devices. You will also learn how to build a custom installer so that end users can deploy applications to a Windows Mobile device through a set up application on their desktop computers.

The following is an overview of the steps that you need to perform in order to create an installation package for a Windows Mobile application:

  • Create the Windows Mobile application.
  • Package the Windows Mobile application into a CAB file.
  • Create a custom installer to install the Windows Mobile application.
  • Create a setup.ini file to describe the Windows Mobile application as its associated CAB file.
  • Create a Setup project to package the CAB file, custom installer, and setup.ini files.

Creating the Application

Figure 1. Hello World! This simple Pocket PC application is what I will use to demonstrate the deployment capabilities.

For this article, I will create a simple Windows Mobile 5.0 application using Visual Studio 2005, which I will use to demonstrate the deployment functionality. If you want to follow along with my demo, create a new Device Application Project in Visual Studio and name it C:SampleApp (see Figure 1).

For simplicity, this application will just contain a Button control that displays a “Hello Pocket PC World!” message when clicked (see Figure 1). The content of this application is not important; I just want to show how you can deploy this application.

Packaging CAB Files
The first step toward deploying the project is to first package the application into a Cabinet (CAB) file. The CAB file can then be deployed to devices, where it is then expanded and installed. A CAB file is an executable archive file that contains your application, dependencies such as DLLs, resources, Help files, and any other files you want to include in it.

Figure 2. Name Your Product: Set the ProductName property of the SmartDeviceCab1 project to MySampleApp.

In this step not only will I create the CAB file for the application, but I will also configure it so that a shortcut is created on the user’s Start menu when they install the application.

Add a new project to your current solution by going to File(Add Project…. In the Project Types column, expand the Other Project Types node and select Setup and Deployment. Select the Smart Device CAB Project template. Name the project C:SmartDeviceCab1 and click OK.

In Solution Explorer, click the SmartDeviceCab1 project and set the ProductName property to MySampleApp (see Figure 2). This will be the name of the folder that is created on the Pocket PC when you install the application.

Right-click on SmartDeviceCab1 in Solution Explorer and select Properties. Set the output file name to DebugSampleApp.cab (see Figure 3). This will be the name and location of the CAB file.

The next step would be to configure how the CAB file will install on the target device when it is deployed onto the user’s Pocket PC. For my example, I will create a shortcut on the user’s Pocket PC Start Menu so that users can directly launch the application from the Start Menu.

In the File System pane, right-click Application Folder and select Add?>Project Output…. In the Add Project Output Group window, select Primary output and click OK.


Figure 3. Finding the CAB: Specify the name and location of the CAB file.
 
Figure 4. Get Shorty: Create a shortcut so that end users can launch your application easily from their Start menus.

Right-click on Primary output from SampleApp(Active) and select Create Shortcut to Primary output from SampleApp (Active) (see Figure 4). The Primary Output refers to the application that will be expanded from the SampleApp.cab cabinet file and here we are creating a shortcut to point to the application.

Rename the default shortcut “SampleApp v1.” This will be the shortcut that you will display on the Start menu of the end user devices (you will create the shortcut in the next step).

In the current window, right click on File System on Target Machine and select Add Special Folder?>Start Menu Folder (see Figure 5). This will allow us to put the shortcut we created earlier into the Start Menu folder on the target Pocket PC. If a Start menu already exists on the device simply skip to the next step.


Figure 5. At the Start: Add a special folder (Start Menu) to the target machine.
 
Figure 6. Taking a Shortcut: Move the shortcut to the Start Menu folder.

The icon for the SampleAppv1 shortcut should be visible from the current window. Drag and drop it onto the Start Menu Folder. The Start Menu Folder should now look like Figure 6. This will cause a shortcut to be created on the user’s Pocket PC Start Menu when the application is installed.

The next step is to generate the CAB file. To do that, go to Build?>Build SmartDeviceCab1 to build the CAB file project.

The CAB file is, in itself, an installer, but only end users with above-average computer savvy will know what to do with it. The next step is to actually make a Windows-style application installer that better mimics the typical experience installing applications on PCs.

Creating the Custom Installer
The previous step creates the CAB file for your application. Technically, this is sufficient for users to install your application onto their Pocket PCs. However, users would need to know how to transfer the CAB file into their Pocket PC and then tap on the CAB file with the stylus to start the installation process. A better solution would be to create a Windows setup application that automates the installation process. To do this, you need to write some code to invoke the Windows CE App Manager. The App Manager performs application installation on a Pocket PC device and is included as part of ActiveSync. ActiveSync is the application that allows users to synchronize their Pocket PCs with their computer. ActiveSync works with Windows Mobile devices such as Pocket PCs and Smartphones.

To get started, add a new project to your current solution by going to File?>Add Project…. Click the Windows project type and select the Class Library template. Name the project CustomInstaller and click OK.

You need to add two references to your project. To do so, right-click on CustomInstaller in the Solution Explorer and select Add Reference … The references to add are System.Configuration.Install and System.Windows.Forms. The System.Configuration.Install namespace provides classes that allow you to write custom installers for your own components, while you need the System.Windows.Forms namespaces for classes that allows you to interact with users through the Windows UI (such as MessageBox, etc).

Double-click Class1.vb in Solution Explorer and populate the file with the following code?the SetupApp class:

Imports System.Windows.FormsImports System.DiagnosticsImports System.ReflectionImports System.IOImports Microsoft.Win32 _Public Class SetupApp    Inherits System.Configuration.Install.Installer    Private Const INI_FILE As String = "setup.ini"    Private Sub Installer_AfterInstall(ByVal sender As Object, _       ByVal e As System.Configuration.Install.InstallEventArgs) _       Handles MyBase.AfterInstall        '---to be executed when the application is installed---        Dim ceAppPath As String = GetWindowsCeApplicationManager()        If ceAppPath = String.Empty Then            Return        End If        Dim iniPath As String = GetIniPath()        Process.Start(ceAppPath, iniPath)    End Sub    Private Sub Installer_AfterUninstall(ByVal sender As Object, _      ByVal e As System.Configuration.Install.InstallEventArgs) _      Handles MyBase.AfterUninstall        '---to be executed when the application is uninstalled---        Dim ceAppPath As String = GetWindowsCeApplicationManager()        If ceAppPath = String.Empty Then            Return        End If        Dim iniPath As String = GetIniPath()        Process.Start(ceAppPath, String.Empty)    End Sub    Public Shared Function GetWindowsCeApplicationManager() As String        '---check if the Windows CE Application Manager is installed---        Dim ceAppPath As String = KeyExists()        If ceAppPath = String.Empty Then            MessageBox.Show("Windows CE App Manager not installed", _                            "Setup", MessageBoxButtons.OK, _                            MessageBoxIcon.Error)            Return String.Empty        Else            Return ceAppPath        End If    End Function    Public Shared Function GetIniPath() As String        '---get the path of the .ini file---        Return """" & _           Path.Combine(Path.GetDirectoryName( _           System.Reflection.Assembly. _           GetExecutingAssembly().Location), "Setup.ini") & """"    End Function    Private Shared Function KeyExists() As String        '---get the path to the Windows CE App Manager from the registry---        Dim key As RegistryKey = _           Registry.LocalMachine.OpenSubKey( _           "SOFTWAREMicrosoftWindowsCurrentVersionApp PathsCEAPPMGR.EXE")        If key Is Nothing Then            Return String.Empty        Else            Return key.GetValue(String.Empty, String.Empty)        End If    End FunctionEnd Class

This class contains the logic to invoke the Windows CE App Manager application so that your application can be installed onto the user’s Pocket PC via ActiveSync.

The SetupApp class contains two events and three methods:

  • Installer_AfterInstall event?this event is fired after the installation process has started
  • Installer_AfterUninstall event?this event is fired after the un-install process has started
  • GetWindowsCeApplicationManager?returns the path containing the Windows CE App Manager.
  • GetIniPath?returns the path of the Setup.ini file
  • KeyExists?checks if the Windows CE App Manager is present on the local machine by checking against the registry

The SetupApp inherits from the Installer class and is marked with the RunInstallerAttribute set to true (). Therefore, Visual Studio’s Custom Action Installer or the InstallUtil.exe will be invoked when the assembly is installed. Essentially, during the installation time, the SetupApp class will first check if the Windows CE App Manager is present on the system. If it is present, the application is then installed using the Windows CE App Manager.

Author’s Note: For a detailed discussion on building custom installers in .NET, check out “Building Custom Installer Classes in .NET.”

Once you’ve added the class, it’s time to build the custom installer project. Right-click on CustomInstaller in Solution Explorer and select Build.

Creating the .ini File
The next step is to create an .ini file to describe the application that you are deploying. This information is used by the Windows CE App Manager.

Using Notepad, create a setup.ini file and save it in C:CustomInstaller. Type the following into the file:

[ceAppManager]Version = 1.0Component = SampleApp[SampleApp]Description = Sample ApplicationUninstall = SampleAppCabFiles = SampleApp.cab
Author’s Note: Author’s Note: MSDN has a good reference document explaining the various fields in an .ini file: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mobilesdk5/html/wce51conCreatingIniFileForApplicationManager.asp.

Creating the Setup Package
With your .ini file created, the final step is to create a setup project to package together all the files that you created earlier. Add a new project to your current solution by going to File?>Add Project….

Figure 7. Adding Files: You now need to add these three files to the Setup project. The file system location for each file is shown to the right of the file name.

Click the Setup and Deployment project type and select Setup Project. Name the project Setup and click OK. Right-click on Setup in Solution Explorer and select Add?>File….Add the following files to the project (see Figure 7):

  • C:CustomInstallerinDebugCustomInstaller.dll
  • C:SmartDeviceCab1DebugSampleApp.CAB
  • C:CustomInstallersetup.ini

Right-click on Setup in Solution Explorer and select View?>Custom Actions. This will display the various types of Custom Actions that are supported. The Custom Actions editor allows you to specify additional actions to be performed on the target computer at the end of an installation. You’ll use the Install type of Custom Action in the next step, which creates the installer bundle. In the Custom Actions pane, right-click Install and select Add Custom Action… (see Figure 8).


Figure 8. Custom Action: Once you’ve selected the custom actions pane, adding an Install custom action takes little more than right click.
 
Figure 9. The Custom Installer: Associate the CustomInstaller.dll with the setup project by picking it and then hitting OK.

This action launches a dialog window. In the “Look in” drop-down list (see Figure 9), select Application Folder. You should see CustomInsaller.dll in the list. Select it and click OK. This is to associate the custom installer application with the setup application.

Now you only need to build the project by right-clicking on Setup in Solution Explorer and selecting Build from the child menu.

Testing the Installation
That’s it! You can now test the setup application by going to C:SetupDebug and double-clicking on Setup (see Figure 10). But before you do that, ensure that your Pocket PC is connected to your computer via ActiveSync.


Figure 10. Installation: Click on the Setup and then select a location to use for your installation folder.
 
Figure 11. Confirmation: This message from the Windows CE Application Manager confirms the completion of the installation routine.

When you’ve done that you’ll be asked for an installation folder; use the default (or whichever folder you would prefer) and click Next. Follow the instructions on the screen and if everything is configured properly, you should see a message from the Windows CE App Manager (see Figure 11). The message asks you to check your mobile device screen to make sure the installation installs correctly.

By connecting your Pocket PC device to the network using ActiveSynch, you should now be able to see the application automatically installed on your Pocket PC (see Figure 12).


Figure 12. Safely Installed: You can confirm that the application installed correctly over ActiveSynch by examining the Start menu (shown here using an emulator).
 
Figure 13. Shortcut Overload: The shortcut will appear in the Programs folder if the Start menu is full.

Tips
Note that if the Start menu is full (or contains too many items), the “SampleApp v1” item will not appear in the Start menu; instead it will appear in the Programs folder (see Figure 13).

Another handy thing to know: You can remove unwanted items in the Start menu using ActiveSync by navigating to the WindowsStart Menu folder and then deleting the unwanted shortcuts from the list displayed as you would delete any file..

More Attention for Your Applications
Creating a better installation experience for your end users may seem like a nice, “extra” thing you can do but you’d be better off to learn to think of it as mandatory. For one, it will help ensure that more users will actually use your application?and might result in fewer calls to the help desk for those who haven’t mastered their mobile devices yet. This article has highlighted the major steps that you need to perform to deploy a typical mobile application for the Pocket PC platform. The steps described can also be used to deploy Smartphone applications, though for Smartphone other deployment techniques are more common?such as deployment through Web servers, SMS, etc.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts