Uninstalling Applications Programmatically in Windows Mobile

Hello there! Since it's the first time I post in this blog, allow me to introduce myself. My name is Jin Zhang and I've been the tester for Application Management for the past year. If you are wondering what Application Management is, it consists of wceload (and related binaries), cabwiz and cabsigntool.

This might be an old topic but doing a quick search online I noticed this question is still being asked. There are several ways to uninstall your application programmatically but perhaps the simplest way to do it is using the Uninstall Configuration Service Provider (CSP). Being able to programmatically do things is always a good thing, but for uninstalling programmatically, perhaps the most common use case would be the ability to remove a program without any user-intervention.

Essentially, you need to "push" an XML file that the Uninstall CSP will process. Provisioning an XML file can be achieved in different ways but for this post I'll go over the API DMProcessConfigXML.

In native code all you need to do is include "cfgmgrapi.h" and call the function:
        DMProcessConfigXML(LPCWSTR pszWXMLin, DWORD dwFlags, LPWSTR* ppszwXMLout)

In managed code, a managed wrapper is provided by the object ConfigurationManager found in the namespace Microsoft.WindowsMobile.Configuration:
        public static XmlDocument ProcessConfiguration ( XmlDocument configDoc, bool metadata)

As for the actual XML string, take the following but replace "Your App" with the name of your application:

<wap-provisioningdoc>
<characteristic type="UnInstall">
<characteristic type="Your App">
<parm name="uninstall" value="1" />
</characteristic>
</characteristic>
</wap-provisioningdoc>

The code above will trigger the uninstall of your application without any prompting. Keep in mind that if your application contains a setup.dll and your Uninstall_Init function displays UI, this might defeat the purpose of a silent uninstall. Of course, you can design your setup.dll in such a way that will not prompt during a programmatically initiated uninstall.

I hope the above will help some of you. If you are burning to know about a specific topic regarding Application Management, leave your comments below and if there is enough interest, I'll consider it as a future topic.

Comments

  • Anonymous
    December 10, 2008
    Hi, Thank you for your blog entry, it is always useful knowing how to perform these kinds of things programmatically. I would be interested in learning more about Application Management. Thanks Paul Diston

  • Anonymous
    December 11, 2008
    Hi, Can you offer any insight into how to remove a program from the "Remove Programs" list after you have installed the CAB? Thanks Dave Shaw

  • Anonymous
    December 11, 2008
    http://msdn.microsoft.com/en-us/library/aa448616.aspx use the /nouninstall parameter on cabwiz.exe: <snip> /nouninstall    Specifies that the application does not appear in the Remove Programs dialog on the target device. When used, the associated application cannot be uninstalled. </snip> <editorial> of course, I don't know if this affects the uninstall CSP or not, and it may or may not be supported on WM2003, or non-Windows Mobile WinCE variants </editorial>

  • Anonymous
    December 11, 2008
    The comment has been removed

  • Anonymous
    December 11, 2008
    Thanks for the replies CC and Jin, but I meant after installation, is there somewhere (I have looked in the registry and in the Windows and Program Files directories) where you can remove the program from the list. On occasions software has been un-installed but the program cannot be removed from the list. Nothing but a Hard Reset can clear it. Thanks Dave

  • Anonymous
    December 12, 2008
    Dave, If an uninstall fails when initiated manually by the user, they should be alerted about the failed uninstall and asked whether they wish to remove the entry or not (even though the uninstall failed). On the other hand, when the uninstall was triggered by the CSP, no such prompt will appear. Unfortunately, your program will not be able to remove this entry this way. This is, however, a scenario that is on our list of considerations for future releases. Thanks, Jin

  • Anonymous
    December 14, 2008
    Hi, I simply want to add that the UnInstall CSP doesn't work when invoked through a CAB or CPF, as I mentioned here (http://blogs.msdn.com/raffael/archive/2008/09/04/provisioning-the-uninstall-configuration-service-provider-fails-if-invoked-through-cab-or-cpf.aspx), but there's a possible workaround if you absolutely require a CAB or CPF provisioning the UnInstall CSP. Cheers, raffaele

  • Anonymous
    February 05, 2009
    Jin, I'm wondering the same thing as DaveShaw. We have a cab that installs files that need to stay on the mobile device between installs of new versions of the application. (database files). The new version of WCELoad requires the removal of the previous version before the installation of the new cab. The Problem is that the removal process, removes the files before the new cab file's setup.dll is called which keeps us from saving any user files. Our option is to change our application name which buys us the abillity to not run the uninstall of the older version, but now we have 2 applications listed in "Remove Programs". What does "Remove Programs" look at to list files? Can we remove this entry via the new setup.dll?

  • Anonymous
    March 01, 2009
    Hi, This type of discussion provides us an insight into many other ideas for developers. I am developing for Windows mobile using smart device win32 console project "my application" in which I need to get the list of all applications(including "my application") that are presently there on the device in which "my application" runs programatically. I have googled in lot of sites but no solution  obtained. Can You kindly help me in this context as soon as possible. Thanks in advance for any help. Regards, Hema.

  • Anonymous
    March 06, 2009
    Hello,  I made kind of library to give my application an "AutoUpdate" feature (using the windows Azure platform for store of version informations and updated CAB files).  I would like to know if there is a way to proper do an uninstall and then install of the app. Today I'm just doing a process start of the updated cab but I don't really like this "dirty update". I would love to be able to do a clean uninstall and then a clean install almost silently (just a restart of the exe of course)... Do you know a clean way to do this ? (process.Start(cabfile); this.killMyself(); is really baaaadddd but didn't find a clean way...)  Thanks for the tip anyway, will be used by some friends I know for doing clean uninstall ^^  See Ya'

  • Anonymous
    May 25, 2009
    The comment has been removed