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;
}
/// <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文件夹外),自己测
试了下,感觉有可行性。