Prerequisitos: Tener una aplicación para Windows Mobile, ya sea para SmartPhone o Handheld, obvio me refiero al código.
Crear un assembly de nombre CustomInstaller.dll con la siguiente clase:
-------------------------------------------------------------------------------------
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using Microsoft.Win32;
[System.ComponentModel.RunInstaller(true)]
public class SetupApp : System.Configuration.Install.Installer
{
private const string INI_FILE = @"\Setup.ini";
public SetupApp()
{
AfterInstall += new System.Configuration.Install.InstallEventHandler(SetupApp_AfterInstall);
AfterUninstall += new System.Configuration.Install.InstallEventHandler(SetupApp_AfterUninstall);
}
void SetupApp_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
//---to be executed when the application is installed---
string ceAppPath = GetWindowsCeApplicationManager();
if ( ceAppPath.Equals(string.Empty) )
return;
string iniPath = GetIniPath();
Process.Start(ceAppPath, iniPath);
}
void SetupApp_AfterUninstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
//---to be executed when the application is uninstalled---
string ceAppPath = GetWindowsCeApplicationManager();
if ( ceAppPath.Equals(string.Empty))
return;
string iniPath = GetIniPath();
MessageBox.Show(iniPath);
Process.Start(ceAppPath, string.Empty);
}
public static string GetWindowsCeApplicationManager()
{
//---check if the Windows CE Application Manager is installed---
string ceAppPath = KeyExists();
if ( ceAppPath.Equals(string.Empty))
{
MessageBox.Show("Windows CE App Manager not installed", "Setup", MessageBoxButtons.OK, MessageBoxIcon.Error);
return string.Empty;
}
return ceAppPath;
}
public static string GetIniPath()
{
//---get the path of the .ini file---
string ini = "\"" + Path.Combine(Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location), "Setup.ini") + "\"";
return ini;
}
public static string KeyExists()
{
//---get the path to the Windows CE App Manager from the registry---
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\CEAPPMGR.EXE");
if (key == null )
return string.Empty;
else
return key.GetValue(string.Empty, string.Empty).ToString();
}
}
-------------------------------------------------------------------------------------
Paso 1: Crear un proyecto de setup Smart Device Cab Project, agregarle el output del proyecto de la aplicación Mobile.
Paso 2: Crear un nuevo proyecto con Visual Studio -> Setup Project, es decir, como si fuéramos a generar un proyecto de instalación común y corriente.
Paso 3: Agregar el cab resultante del paso 1 al proyecto de Setup del paso 2
Paso 4: Agregar un archivo .ini con el siguiente contenido, éste archivo llevará por nombre Setup.ini
[ceAppManager]
Version = 1.0
Component = HomsMobile
[HomsMobile]
Description = HomsMobile Application
Uninstall = HomsMobile
CabFiles = HomsMobileSetup.cab
Nota: Reemplazar HomsMobile por el nombre del proyecto de la aplicación Windows Mobile que vayamos a generar.
Paso 5: Una vez creado el setup.ini, lo agregamos también al proyecto de setup del paso 2
Paso 6: Creamos un Custom Action en el proyecto de setup del paso 2 y lo agregamos en el folder "Install" y agregarmos el assembly de CustomInstaller.dll
Paso 7: Finalizamos
Observaciones:
Una vez que se ha compilado el assembly de CustomInstaller se puede ocupar para proyectos subsecuentes..
El archivo ini no debe llevar retorno de carro en la última línea, si se la dejan ya no funciona.