Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

Learning a simple series of steps in Visual Studio 2005 will make deploying applications to mobile devices a no-brainer from here on out. Follow along with this project, which includes step-by-step instructions, code, and a sample .ini file.




Application Security Testing: An Integral Part of DevOps

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.Forms Imports System.Diagnostics Imports System.Reflection Imports System.IO Imports Microsoft.Win32 <System.ComponentModel.RunInstaller(True)> _ 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( _ "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CEAPPMGR.EXE") If key Is Nothing Then Return String.Empty Else Return key.GetValue(String.Empty, String.Empty) End If End Function End 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 (<System.ComponentModel.RunInstaller(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.0 Component = SampleApp [SampleApp] Description = Sample Application Uninstall = SampleApp CabFiles = 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.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date