Thursday, July 22, 2010

Setup Installer For Windows Mobile Applications

SETUP INSTALLER FOR WINDOWS MOBILE APPLICATIONS

The creation of an installer with Visual Studio is simple, requires little coding, and can be done within the existing Visual Studio Solution for your application, this is the path we need to follow:

1. Create a windows mobile application

2. Create a CAB installation file

3. Create a custom action for the installation

4. Create a windows installer setup application

In this tutorial we are going to focus on steps 3 and 4.

I. CREATING A WINDOWS MOBILE APPLICATION

1. On visual studio select: New Project >>Smart Device>>Device Application

2. Add some components to your form

3. Compile the project

II.CREATING A CAB INSTALLATION FILE

Add a new CAB project by right click the solution and select:

Add >> New Project >> Other Project Types >> Setup and Deployment >> Smart Device CAB Project

Right click on the CAB installer project and select: Add >> Project Output


Select your mobile project then from the list select Primary output


Now to add the Programs Folders on the CAB project, on the File System on Target Machine right click it then click on: Add Special Folder>> Programs Folder


Select Programs Folder on the File System tree, then right click on the empty panel at right and select Create New Shortcut


Select Application Folder >> Primary output, then click ok


Now it is time to add a registry key. Click on the Registry Editor button


 
          And add the string value "HKLM\Software\My Company\My App\Version"
          

You need to create the path key by key, and then add the string value on the right panel.


Name it "Version" and then, select it, and enter "1.0" into the Value field on the Properties Window


Build your project and you will have the CAB file by now.


III.CREATING A CUSTOM ACTION

1. On the File menu, point to Add, and then click New Project. Name the new project MyCustomAction.

2. On the Project menu, click Add New Item. In the template list, click Installer Class. Name the new class MyInstallerClass.

3. In the Solution Explorer pane, right-click MyInstallerClass.cs, and then click View Code.

4. In the code window, create a new method called Commit. This method overrides the Commit method of the base Installer class. Use this method to invoke the application manager. The following code example shows the implementation of Commit.


public override void Commit(System.Collections.IDictionary savedState)
{
// Call the Commit method of the base class
base.Commit(savedState);

// Open the registry key containing the path to the Application Manager
Microsoft.Win32.RegistryKey key = null;
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\microsoft\\windows\\currentversion\\app paths\\ceappmgr.exe");

// If the key is not null, then ActiveSync is installed on the user's desktop computer
if (key != null)
{
// Get the path to the Application Manager from the registry value
string appPath = null;
appPath = key.GetValue(null).ToString();

// Get the target directory where the .ini file is installed.
// This is sent from the Setup application
string strIniFilePath = "\"" + Context.Parameters["InstallDirectory"] + "myApp.ini\"";
if (appPath != null)
{
// Now launch the Application Manager
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = appPath;
process.StartInfo.Arguments = strIniFilePath;
process.Start();
}
}
else
{
// No Active Sync - throw a message
}
}


Now you need to add an .ini file

Create a text file in notepad save it as setup.ini and put the next code:




[ceAppManager]
Version = 1.0
Component = SampleApp

[SampleApp]
Description = Sample Application
Uninstall = Pocket App
CabFiles = YourCab.cab




IV. CREATE A WINDOWS INSTALLER SETUP APPLICATION

  1. On the File menu, point to Add, and then click New Project. In the Project Types tree structure, expand the Other Project Types node. In the Templates pane, click Setup Project. Name the project MyAppSetup.
  2. Right-click on the newly created project in Solution Explorer, point to View, and then select File System. The File System window allows you to control where files are installed on the user's computer. For this example, the files are the .cab and .ini files that the Application Manager will use to install the application on the Windows Mobile device.
  3. To add your application's .cab file, right-click on the Application Folder icon, point to Add, and then click Project Output. In the Project list in the Add Project to Output Group window, select MyAppCab, click Built Outputs, and then click OK.
  4. To add the .ini file for your application, right-click Application Folder icon, point to Add, and then click File. Browse to your .ini file, and then click OK.
  5. Right-click the MyAppSetup project icon in Solution Explorer, point to View, and then click Custom Actions. The Custom Actions window allows you to assign custom actions to be executed for different events in the installation.
  6. In the Custom Actions window, right-click the Install icon, and then click Add Custom Action.
  7. In the Select Item in Project window, click on Application Folder, and then click OK. Click the Add Output button. From the Project list in the Add Project to Output Group window, click MyAppCustomAction, click Primary Output, and then click OK twice. For the commit custom action, repeat steps 6 and 7.
  8. In the Custom Actions window, click Primary Output from MyAppCustomAction in the Commit folder area. In the Properties window, enter the following value for the CustomActionData property: /targetdir="[TARGETDIR]\" this passes the directory in which the .cab and .ini files for your application are installed to the custom action.

Compile your project and execute the .exe file created!


Sources:

http://msdn.microsoft.com/en-us/library/bb158529.aspx

http://www.devx.com/wireless/Article/31198/1954

http://www.mobilepractices.com/2008/02/how-to-create-windows-mobile-smart.html

http://www.devx.com/wireless/Article/31198/1954


No comments:

Post a Comment