Creating an Installer for Windows Mobile Applications

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.

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