获取计算机软件列表,获取计算机已安装软件列表解决方法

获取计算机已安装软件列表

Dear all,

最近小弟在做一个应用程序,就是仿造360软件管家,获取计算机里已安装软件列表,

现思路如下,根据注册表路径:

针对x86系统,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

针对x64系统,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

分别获取已安装软件列表,然后按照以下步骤进行处理:

1.剔除service项,重复项,已安装补丁,如KB开头的子项(计划中,未能实现)

2.合并x86,x64.最终得到软件列表数据

遇到的问题,

1.该实现思路是否正确?

2.思路正确的前提下,如何解决识别为service,重复项,补丁等子项

恳请大侠指教?

TOM

------解决方案--------------------

Microsoft.Win32.RegistryKey   rk   =   Microsoft.Win32.Registry.LocalMachine.OpenSubKey( "SOFTWARE ");

String   []   names   =   rk.GetSubKeyNames();

foreach   (String   s   in   names)

{

//输出吧....

}

------解决方案--------------------

可以用Installer API,详细文档见http://msdn.microsoft.com/en-us/library/aa369426(v=VS.85).aspx。

static void Main()

{

StringBuilder result = new StringBuilder();

for (int index = 0; ; index++)

{

StringBuilder productCode = new StringBuilder(39);

if (MsiEnumProducts(index, productCode) != 0)

{

break;

}

foreach (string property in new string[] { "ProductName", "Publisher", "VersionString", })

{

int charCount = 512;

StringBuilder value = new StringBuilder(charCount);

if (MsiGetProductInfo(productCode.ToString(), property, value, ref charCount) == 0)

{

value.Length = charCount;

result.AppendLine(value.ToString());

}

}

result.AppendLine();

}

Console.WriteLine(result.ToString());

}

[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, StringBuilder lpValueBuf, ref int pcchValueBuf);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值