How to uninstall a Windows Mobile Application through CSP Programming

Source: Internet
Author: User

 

How to uninstall a Windows Mobile Application through CSP ProgrammingProgram

Yellow winter

Http://fox23.cnblogs.com/

Summary

Like Windows PC, Windows Mobile also provides control panel items for deleting applications, but sometimes we need to uninstall another program in the program, or uninstall the application itself, this situation is very common in enterprise applications. In this case, the system configuration service file CSP (configuration service providers) is used ). This article describes how to use CSP to uninstall an application installed on Windows Mobile.

 

Simplest solution

If CSP is not used, you can call out the control panel items of the system-provided deletion program in the program.

Figure 1

This method is relatively simple, the followingCodeThis function is implemented:

Code
Processstartinfo startinfo =   New Processstartinfo ();
Startinfo. filename =   @" \ Windows \ ctlpnl.exe " ;
Startinfo. Arguments =   " Cplmain. CPL, 10 " ;
Process. Start (startinfo );

For details about how to call the control panel provided by the system, refer to this article.Article:

Http://www.cnblogs.com/fox23/archive/2008/11/14/showing-windows-mobile-control-panel-programmatically.html

CSP Introduction

Although the above method is simple, it cannot directly control the deletion of specific programs in the program. If you are the company's IT administrator, I think you should not let this happen, then you need to use CSP. What is CSP? Configuration Service Providers (CSP) is a group of interfaces that use XML to query and modify system settings. The XML file here is called the Oma client provisioning (WAP-based) XML file. For more information about CSP support for Windows Mobile, see this article:

Http://msdn.microsoft.com/en-us/library/bb737536.aspx

Windows Mobile provides programming interfaces for posting csp xml files similar to WAP-PUSH:

Hresult dmprocessconfigxml (

Lpcwstr pszwxmlin,

DWORD dwflags,

Lpwstr * ppszwxmlout

);

This function is defined in the header fileCfgmgrapi. h.

The following example shows how to add an IE favorites item through CSP:

 

Code
// Define XML provision File
Lpcwstr g_wszfavoritexml =  
L " <WAP-provisioningdoc> "
L " <Characteristic type = \ " Browserfavorite \ " > "
L " <Characteristic type = \ " Cnblog \ " > "
L " <Parm name = \ " URL \ " Value = \ " HTTP: // Www.cnblogs.com // >"
L " </Characteristic> "
L " </Characteristic> "
L " </WAP-provisioningdoc> " ;
 
Hresult AddFavorite ()
{
Hresult HR = E_fail;
Lpwstr wszoutput = NULL;
HR = Dmprocessconfigxml (g_wszfavoritexml, export flag_process, & Wszoutput );

//Delete the useless return value. It is still an XML string.
Delete [] wszoutput;

ReturnHR;
}

The managed encapsulation of this method is also provided on devices after Windows Mobile 5, that is, the processconfiguration static method of the configurationmanage class.

Use CSP to delete specific applications

 

First, you need to check whether the application can be deleted. In fact, we have this option when creating the installation package (CAB) Through Visual Studio, that is to say, you can prevent your program from being deleted (it cannot be deleted through the system's deletion program ). Here, through CSP, we can only uninstall programs that are allowed to be uninstalled. An example is provided in msdn to query programs that can be deleted. For more information, see this example. I created a smart device cab project named "testcab" in advance ". For example, it is easy to write C # Code as follows:

 

Code
String Query =   " <WAP-provisioningdoc> <characteristic type = \ " Uninstall \ " > <Characteristic-query type = \ " Testcab \ " /> </Characteristic> </WAP-provisioningdoc> " ;
Xmldocument xdoc =   New Xmldocument ();
Xdoc. loadxml (query );
Xdoc = Configurationmanager. processconfiguration (xdoc, True );

The returned xdoc is as follows:

 

Figure 2

The result shown in Figure 2 is not the same as that given in the msdn example. So I went to the built-in "delete program" and looked at it. 1, the name of the program to be deleted here is the name of the cab package plus the name of manufacturer. You can set these two names when creating a cab project in Visual Studio. After compilation, you can find an INF file in the directory where the cab is located, which contains the installation information. You can view the appname and manufacturer items as follows:

[Cestrings]

Appname = "testcab"

Installdir = % CE1 % \ % appname %

[Strings]

Manufacturer = "freesc" 

So here, we only need to modify the XML query string in the original program:
"<WAP-provisioningdoc> <characteristic type = \" Uninstall \ "> <characteristic-query type = \" freesc testcab \ "/> </characteristic> </WAP-provisioningdoc>"

The correct return value is as follows:

Figure 3

Compare figure 2 and Figure 3. You only need to parse the XML return value to learn the installation status of an application. For example, here we can judge xmldocument. selectsinglenode ("// characteristic/characteristic") returns NULL to know whether the application is installed and can be uninstalled. The following program demonstrates how to uninstall the test app:

Code
Doc =   New Xmldocument ();
String XML =   @"
<WAP-provisioningdoc>
<Characteristic type = "" Uninstall "">
<Characteristic type = "" freesc testcab "">
<Parm name = "" Uninstall "" value = "" 1 ""/>
</Characteristic>
</Characteristic>
</WAP-provisioningdoc> " ;
Doc. loadxml (XML );
Configurationmanager. processconfiguration (Doc, True );

 

Write your own Application Manager

After learning about the above content, you can easily compile your own application manager. The following is a simple example. The code is downloaded in the following link:

 

Complete code: Click here to download

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.