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

MrDawn 2013-05-08 04:01:36
想做一个软件启动时要检查硬件设备是否已经安装驱动,谷歌了,也百度了,没找到答案,现在换种思维,想先获得电脑上所有已经安装的软件,然后在和驱动软件名对比,有则已经安装了该驱动。问题是怎样获取电脑上安装的所有软件呢?
要求:能获取控制面板中程序里面列出来的所有软件??
网上搜到的两种方法都不行,第一种是读注册表
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);

两种都试了,均不能获得控制面板程序里的所有软件?呼吁高手支招!!!!!!
...全文
628 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
异常异长 2013-08-09
  • 打赏
  • 举报
回复
貌似查找注册表是最靠谱的吧。
Wshysh 2013-08-08
  • 打赏
  • 举报
回复
楼主现在实现了吗?求发邮箱。 #4的能不能把完整的程序发给我参考下。 邮箱1021398847@qq.com
jickie阿文 2013-05-10
  • 打赏
  • 举报
回复
  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);
        }
MrDawn 2013-05-10
  • 打赏
  • 举报
回复
那怎么办,谁知道C#怎样检查驱动,csdn真的没高手了吗
dylike 2013-05-08
  • 打赏
  • 举报
回复
软件和驱动不是一个类了,不能一起做吧.已经安装的软件可以到注册表找SOFTWARE

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧