您的位置:首页 > 移动开发

ManageApps:C#读取Windows系统中的已经安装的程序并卸载软件

2012-09-25 15:54 211 查看
可以使用C#来操作注册表来获取当前Windows系统中的已经安装的软件或程序,当然,也可以用来卸载软件了。

【网通】点击这里下载全部源程序 【电信、网通】点击这里下载源程序

【下载说明】

1、单击上面这个地址,打开下载页面。

2、点普通下载--等待30秒--点“下载”按钮--保存






主要源程序:

/*
* Created by SharpDevelop.
* User: PJ
* Date: 2012-7-13
* Time: 15:20
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

using Microsoft.Win32;

namespace ManageApps
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
private List<string> apps=new List<string>();

public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
LoadApps();
}

void LoadApps()
{
string tempType = null;
object displayName = null, uninstallString = null,releaseType = null;
RegistryKey currentKey = null;
int softNum = 0;
RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");

try
{
listBox1.Items.Clear();
apps.Clear();

foreach(string item in pregkey.GetSubKeyNames())
{
currentKey = pregkey.OpenSubKey(item);
displayName = currentKey.GetValue("DisplayName");
uninstallString = currentKey.GetValue("UninstallString");
releaseType = currentKey.GetValue("ReleaseType");

bool isSecurityUpdate = false;

if(releaseType != null)
{
tempType = releaseType.ToString();
if(tempType == "Security Update" || tempType == "Update")
isSecurityUpdate = true;
}

if( !isSecurityUpdate && displayName != null && uninstallString != null)
{
listBox1.Items.Add(displayName.ToString());

apps.Add(displayName.ToString() + "," + uninstallString.ToString());

softNum++;
label1.Text = softNum.ToString() + " Apps";
}
}
}
catch(Exception e)
{
MessageBox.Show(e.Message.ToString(),"Exception");
}
finally
{
pregkey.Close();
}
}

void RunDosCommand(string cmd)
{
Process p=new Process();
p.StartInfo.FileName="cmd.exe";
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardInput=false;
p.StartInfo.Arguments="/c "+cmd;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.CreateNoWindow=true;
p.Start();
p.WaitForExit();
p.Close();
}

void BtnUninstallClick(object sender, EventArgs e)
{
int selectIndex = listBox1.SelectedIndex;
string selectText = listBox1.Items[selectIndex].ToString();
string uninstallString = null;

//MessageBox.Show(selectText);

for(int i=0;i<apps.Count;i++)
{
if(apps[i].Split(',')[0] == selectText)
{
uninstallString = apps[i].Split(',')[1];
break;
}
}

RunDosCommand(uninstallString);
}

void BtnRefreshClick(object sender, EventArgs e)
{
tbxFilter.Text="";

LoadApps();
}

void TbxFilterTextChanged(object sender, EventArgs e)
{
string filterText = tbxFilter.Text.ToLower();

if(filterText.Trim() != "")
{
listBox1.Items.Clear();

for(int i=0;i<apps.Count;i++)
{
if(apps[i].Split(',')[0].ToLower().Contains(filterText))
{
listBox1.Items.Add(apps[i].Split(',')[0]);
}
}
}
else
LoadApps();
}
}
}

【更多阅读】

[原]使用Excel的VBA来读取和修改bmp位图像素数据
[原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
[原]《The C Programming Language》电子书下载
[原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
[原]GetAlpha:C#实现获取网页验证码图片,并识别出其中的字母
[原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
[译]C#控制计算机的并口LPT
[译]在C# .NET2.0实现单实例应用程序
[译]在C# .NET2.0实现单实例应用程序
[译]C#控制计算机的并口LPT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐