随笔 - 224  文章 - 41  trackbacks - 0
<2010年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

享受编程

常用链接

留言簿(11)

随笔分类(159)

随笔档案(224)

文章分类(2)

文章档案(4)

经典c++博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

原文地址:http://hi.baidu.com/guigangsky/blog/item/da375f319a3f6a1ceac4af01.html/cmtid/c6ef9651d58acb15377abef1

//Registry.ClassesRoot   对应注册表 HKEY_CLASSES_ROOT
//Registry.CurrentConfig 对应注册表 HKEY_CURRENT_CONFIG
//Registry.CurrentUser   对应注册表 HKEY_CURRENT_USER
//Registry.LocalMachine   对应注册表 HKEY_LOCAL_MACHINE
//Registry.Users   对应注册表 HKEY_USERS

using System;
using Microsoft.Win32;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string temp = null, 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
            {
                foreach (string item in pregkey.GetSubKeyNames())               //循环所有子键
                {
                    currentKey = pregkey.OpenSubKey(item);
                    displayName = currentKey.GetValue("DisplayName");           //获取显示名称
                    uninstallString = currentKey.GetValue("UninstallString");   //获取卸载字符串路径
                    releaseType = currentKey.GetValue("ReleaseType");           //发行类型,值是Security Update为安全更新,Update为更新
                    bool isSecurityUpdate=false;
                    if (releaseType != null)
                    {
                        tempType = releaseType.ToString();
                        if (tempType == "Security Update" || tempType == "Update")
                            isSecurityUpdate = true;
                    }
                    if (!isSecurityUpdate && displayName != null && uninstallString != null)
                    {
                        softNum++;
                        temp += displayName.ToString() + Environment.NewLine;
                    }
                }
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message.ToString());
            }
            tbSoftWare.Text = "共有软件" + softNum.ToString() + "个"+ Environment.NewLine + temp;
            pregkey.Close();
        }

    }
}

posted on 2010-06-12 17:37 漂漂 阅读(4149) 评论(0)  编辑 收藏 引用 所属分类: c#开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理