Creating an Installer for Windows Mobile Applications
Windows Mobile SupportedWindows Embedded CE Not Supported
8/28/2008

When deploying your Windows Mobile application, you may want to create an installer that runs on the user's desktop and invokes the Application Manager to install your application on the user's device. The creation of an installer with Visual Studio 2005 is simple, requires little coding, and can be done within the existing Visual Studio Solution for your application.

How to create a custom action

  1. Make sure that Solution Explorer for your project is visible. On the File menu, point to Add, and then click New Project. You can create your custom action in native or managed code. For this example, choose a Visual C#-based Class Library 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
      }
    }
How to create a Windows Installer Setup Application

  1. Make sure that Solution Explorer for your project is visible. 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 powered 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.

Tags :


Community Content

Thomas Lee
Small typo

The string identifier in the overridden Commit method has to be identical to the CustomActionData property when retrieving the stored value from the context.
Since the property is set to '/targetdir="[TARGETDIR]"', retrieving the value should look like this:

string strIniFilePath = "\"" + Context.Parameters["targetdir"] + "myApp.ini\"";


and not:

string strIniFilePath = "\"" + Context.Parameters["InstallDirectory"] + "myApp.ini\"";


Caused me some headache as everything compiled just fine and I started looking elsewhere.

-Larantz-

Tags : contentbug

Thomas Lee
Visual Studio 2008
The code above will not work with VS 2008

-Mark-
Tags : vs2008

Karmel M
Works with VS 2008
I actually wrote it with VS 2008, and it absolutely works.
-Karmel
Tags :

Thomas Lee
Alternative Installer Creation Tools
There are alternatives for setup creation. For example for those who don't have the professional version of visual studio. On such application is Mobile Packager (www.mobilepackager.com).

Tags :

Thomas Lee
Windows Mobile device error: Installation of MyApp.CAB was unsuccessful.

[tfl - 01 07 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at

http://www.microsoft.com/communities/newsgroups/en-us/ . You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C &
SQL Server :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C &
.NET Framework :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C &


Page view tracker