当前位置:编程学习 > C#/ASP.NET >>

c# 怎么获取电脑上安装的所有软件(急!!!!)

想做一个软件启动时要检查硬件设备是否已经安装驱动,谷歌了,也百度了,没找到答案,现在换种思维,想先获得电脑上所有已经安装的软件,然后在和驱动软件名对比,有则已经安装了该驱动。问题是怎样获取电脑上安装的所有软件呢?
要求:能获取控制面板中程序里面列出来的所有软件??
网上搜到的两种方法都不行,第一种是读注册表
string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
            {

                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
        省略...
第二种是导入两个动态链接库
 [DllImport("msi.dll",SetLastError=true)]
        static extern int MsiEnumProducts(int iProductIndex,StringBuilder lpProductBuf);
       [DllImport("msi.dll", SetLastError = true)]
       static extern int MsiGetProductInfo(string szProduct,string szProperty,[Out]StringBuilder lpValueBuf,[In,Out] ref int pcchValueBuf);

两种都试了,均不能获得控制面板程序里的所有软件?呼吁高手支招!!!!!! c# 获取电脑上安装的所有软件,急 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 软件和驱动不是一个类了,不能一起做吧.已经安装的软件可以到注册表找SOFTWARE --------------------编程问答-------------------- 那怎么办,谁知道C#怎样检查驱动,csdn真的没高手了吗 --------------------编程问答--------------------
  public static void DisplayInstalledApps(RegistryKey key)
       {
           string displayName;
           if (key != null)
           {
               foreach (String keyName in key.GetSubKeyNames())
               {
                   RegistryKey subkey = key.OpenSubKey(keyName);
                   displayName = subkey.GetValue("DisplayName") as string;
                   if (!string.IsNullOrEmpty(displayName))
                   {
                       Console.WriteLine(displayName);
                   }
               }
           }
       }

        public static void ShowAllSoftwaresName()
        {
            RegistryKey key;

            // search in: CurrentUser
            key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
            DisplayInstalledApps(key);
            // search in: LocalMachine_32
            key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
            DisplayInstalledApps(key);
            // search in: CurrentUser_64
            key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
            DisplayInstalledApps(key);
            // search in: LocalMachine_64
            key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
            DisplayInstalledApps(key);
        }
--------------------编程问答-------------------- 楼主现在实现了吗?求发邮箱。
#4的能不能把完整的程序发给我参考下。
邮箱1021398847@qq.com --------------------编程问答-------------------- 貌似查找注册表是最靠谱的吧。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,