admin管理员组文章数量:1548776
获取计算机已安装软件列表
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/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);
版权声明:本文标题:获取计算机软件列表,获取计算机已安装软件列表解决方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727218217a1103280.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论