free web page counters

Windows Mobile Pocket PC Smartphone Programming

==>Click here for the SiteMap<==. Original contents with decent amount of source codes.

Thursday, March 09, 2006

Programmatically unInstall/remove/delete one program in Windows Mobile devices

====>SiteMap of this Blog<===

Programmatically unInstall/remove/delete one program in Windows Mobile devices

Sometimes you need to provide functionality to programmatically unInstall/remove/delete a program from a user's device. Let us think about a use case: Your program is managing some private or sensitive data. Unfortunately the user lose the device, or some one stolen the device. Either case, the capability to remotely destroy the program and data is highly desired. If you are targeting enterprise customer, this remote-destroy functionality is almost certain listed as one of MUST-Have features.

How to send a signal to or notify a lost device is the other story that I might talk later in another blog post, here I solely focus on how to programmatically unInstall a program in Windows Mobile devices.

Pocket PC 2003 platform

In Pocket PC 2003 devices, you can simply execute "\Windows\unload.exe" and pass program name as the parameter. I guess you should know your own program's name :)

  • The program name is the concatenation of "Provider" and "AppName" specified in your .INF file (the file for cabwiz to build)
  • The program name is listed in the list of "Settings" => "System" => "Remove Programs"

You can call either CreateProcess or ShellExecuteEx to spawn unload.exe. If you want to be a little more prefessional, call WaitForSingleObject on the handle to the new process returned by both calls. Remember to close those handles!

Other newer platforms (Pocket PC 5.0, Smartphone 2003, Smartphone 5.0)

The simple method of running unload.exe does not work in newer Windows Mobile platforms: Smartphone 2003, Pocket PC 5.0, Smartphone 5.0. Microsoft wants to move anything regarding mobile device management and configuration to its CSP (Configuration Service Provider) architecture. UnInstalling program is one CSP. UnInstall Configuration Service Provider uninstalls applications from the device. A provisioning document that contains XML to uninstall an application should contain only that XML and no other provisioning information.

MSDN documentation states that using UnInstall CSP is "the
cleanest way to uninstall an application under the transactioning model for
Windows Mobile Version 5.0 software for Smartphones
". Actually it is also the case for Smartphone 2003 device.

Below is a code snippet for such purpose:


   // build an XML for UnInstallation
   // using stack , sloppy code
   TCHAR szProvXML[512];
   LPTSTR szPvXMLOut = NULL;
   memset(szProvXML, 0, 512*sizeof(TCHAR));
   wcscat(szProvXML, TEXT("<wap-provisioningdoc><characteristic type=\"UnInstall\"><characteristic type=\""));
   wcscat(szProvXML, TEXT("TestingApp"));
   wcscat(szProvXML, TEXT("\">"));
   wcscat(szProvXML, TEXT("<parm name=\"uninstall\" value=\"1\"/>"));
   wcscat(szProvXML, TEXT("</characteristic></characteristic></wap-provisioningdoc>"));
   HRESULT hr = DMProcessConfigXML(szProvXML, CFGFLAG_PROCESS, &szPvXMLOut);



Category: [Setup / Install / unInstall / Upgrade]

====>SiteMap of this Blog<===