Thursday, December 11, 2008

Geeks Only Today

Uninstalling Applications Programmatically in Windows Mobile is the title of a blog post from Jim Zhang.

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:



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

No comments: