Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
4/14/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 Filemenu, 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 Libraryproject. Name the new project MyCustomAction.

  2. On the Projectmenu, 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 Commitmethod of the base Installerclass. Use this method to invoke the application manager. The following code example shows the implementation of Commit.

    Copy Code
    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 Filemenu, point to Add, and then click New Project. In the Project Typestree structure, expand the Other Project Typesnode. In the Templatespane, 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 Systemwindow 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 Foldericon, point to Add, and then click Project Output. In the Projectlist in the Add Project to Output Groupwindow, select MyAppCab, click Built Outputs, and then click OK.

  4. To add the .ini file for your application, right-click Application Foldericon, point to Add, and then click File. Browse to your .ini file, and then click OK.

  5. Right-click the MyAppSetupproject icon in Solution Explorer, point to View, and then click Custom Actions. The Custom Actionswindow allows you to assign custom actions to be executed for different events in the installation.

  6. In the Custom Actionswindow, right-click the Installicon, and then click Add Custom Action.

  7. In the Select Item in Projectwindow, click on Application Folder, and then click OK. Click the Add Outputbutton. From the Projectlist in the Add Project to Output Groupwindow, click MyAppCustomAction, click Primary Output, and then click OKtwice. For the commit custom action, repeat steps 6 and 7.

  8. In the Custom Actionswindow, click Primary Output from MyAppCustomActionin the Commitfolder area. In the Propertieswindow, enter the following value for the CustomActionDataproperty: /targetdir="[TARGETDIR]\".This passes the directory in which the .cab and .ini files for your application are installed to the custom action.