首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#获取本机已装配软件方法

2013-02-24 
C#获取本机已安装软件方法新手代码,老鸟请勿喷。using Systemusing System.Collections.Genericusing Sys

C#获取本机已安装软件方法
新手代码,老鸟请勿喷。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace 获取已安装程序列表
{
    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());
            }
            richTextBox1.Text = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
            pregkey.Close(); 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}


[解决办法]
多谢楼主分享,那么晚还孜孜不倦
[解决办法]
有空看看,收了,很好
[解决办法]
路过,精神可嘉.有空帮你测试一下
[解决办法]
thanks for your sharing.
[解决办法]
楼主好人,鬼节快乐!
[解决办法]
呵呵,谢谢分享
[解决办法]
引用:
引用:

楼主好人,鬼节快乐!

不说鬼节我还真忘了

呵呵
[解决办法]
弄老不错了。


[解决办法]
原来是分享帖,谢谢分享
[解决办法]
要是能根据获取出来的程序,知道安装目录就好了.

[解决办法]
lz,不错,收藏了。


[解决办法]
帮你简化一了一下:


        private void GetProcessName()//
        {
            listBox1.Items.Clear();
            foreach (Process p in Process.GetProcesses())
            {
                listBox1.Items.Add(p.ProcessName);
            }

            label1.Text = "统计:" + listBox1.Items.Count.ToString();
        }        

[解决办法]
其实就是个注册表操作。。

热点排行