zoukankan      html  css  js  c++  java
  • C# 获取系统安装程序列表及卸载程序

           首先添加引用Microsoft.WindowsMobile.Configuration。往界面中拖入控件ListBox,
           下面为部分代码:

           

    代码
    private XmlDocument doc;

            
    /// <summary>
            
    /// 列出PDA上已安装的程序
            
    /// </summary>
            
    /// <param name="lb">待填充列表</param>
            private void ListApps(ListBox lb)
            {
                doc 
    = new XmlDocument();
                
    //具体原理还要学习下
                doc.LoadXml(@"<wap-provisioningdoc><characteristic-query 

    type=""UnInstall"" /></wap-provisioningdoc>
    ");
                XmlDocument ret 
    = ConfigurationManager.ProcessConfiguration(doc, 

    true);
                XmlNodeList list 
    = ret.SelectNodes("//characteristic/characteristic");
                lb.Items.Clear();
                lb.SuspendLayout();
                
    foreach (XmlNode xn in list)
                {
                    lb.Items.Add(xn.Attributes[
    "type"].Value);
                }
                lb.ResumeLayout(
    false);
            }


            
    /// <summary>
            
    /// 对选中的程序卸载
            
    /// </summary>
            
    /// <param name="appName">程序名</param>
            private void UnInstall(string appName)
            {
                Cursor.Current 
    = Cursors.WaitCursor;
                doc 
    = new XmlDocument();
                
    string xml = @"
                <wap-provisioningdoc>
                    <characteristic type=""UnInstall"" >
                        <characteristic type=""{0}"" >
                            <parm name=""uninstall"" value=""1"" />
                        </characteristic>
                    </characteristic>
                </wap-provisioningdoc>
    ";
                doc.LoadXml(
    string.Format(xml, appName));
                ConfigurationManager.ProcessConfiguration(doc,
    true);
                ListApps(listBox1);
                Cursor.Current 
    = Cursors.Default;
            }

    其实也可以用列举windows\AppMgr下的所有文件夹名(除Install文件夹外),自己测

    试了下,感觉有可行性。

  • 相关阅读:
    UVA 10462 Is There A Second Way Left?(次小生成树&Prim&Kruskal)题解
    POJ 1679 The Unique MST (次小生成树)题解
    POJ 2373 Dividing the Path (单调队列优化DP)题解
    BZOJ 2709 迷宫花园
    BZOJ 1270 雷涛的小猫
    BZOJ 2834 回家的路
    BZOJ 2506 calc
    BZOJ 3124 直径
    BZOJ 4416 阶乘字符串
    BZOJ 3930 选数
  • 原文地址:https://www.cnblogs.com/MyLucifer/p/1635121.html
Copyright © 2011-2022 走看看