Creating an Installer for Windows Mobile Applications

Windows Mobile 6.5
4/19/2010

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 is simple, requires little coding, and can be done within the existing Visual Studio Solution for your application.

  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
      }
    }
    
  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 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.

Community Content Add
Annotations FAQ
i am unable find the Installer Class in Windows mobile apps
Hi

I am unable to find the installer class for the windows mobile application .Where i can find it ? I am working with windows mobile 5.0 and VS2008 .

Windows 7 !!
How can I use this solutions under Windows 7
This solution is not working for me.
This solution is not working me with Windows 7 and Windows Mobile Device Manager 6.1.

The error text is this: 
Application manager cannot install this application on your mobile device due to an invalid setup file reinstall and try again.

Has somebody any idea?
INI file information
Check out this MSDN article for INI file information needed by App Manager.
http://msdn.microsoft.com/en-us/library/bb158614.aspx
Where does the "myApp.ini" file come from?
I have followed the steps here, but I don't see the "myApp.ini" file anywhere in any of my CAB or Setup projects?? Should the .ini file be auto-generated by Visual Studio, or should it be created by hand?

Check out this article: http://msdn.microsoft.com/en-us/library/bb158614.aspx
Works great.
The approach was very helpful.  I'd like to include uninstall functionality as well, so when the user removes the app through the Windows side add/remove programs, it will trigger CeAppMgr to uninstall the app from the device.  Is this possible?
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 &

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

-Mark-
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).
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-

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