找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 5268|回复: 4

【VB】列出当前安装的程序(不全)

[复制链接]
发表于 2014-12-26 23:43:26 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
20141226234011.png
原理是读取注册表的HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall里面的子项。
这个并不能显示出和【控制面板->添加与删除程序】一样的结果,只是把有Windows卸载器的程序都显示出来了。
核心代码:
  1. Dim ErrNo As Long

  2. Private Const HKEY_LOCAL_MACHINE = &H80000002
  3. Private Const ERROR_SUCCESS = 0&
  4. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyW" (ByVal hKey As Long, lpSubKey As Any, phkResult As Long) As Long
  5. Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyW" (ByVal hKey As Long, lpClass As Any, lpcbClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As Any) As Long
  6. Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyW" (ByVal hKey As Long, ByVal dwIndex As Long, lpName As Any, ByVal cbName As Long) As Long
  7. Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueW" (ByVal hKey As Long, ByVal dwIndex As Long, lpValueName As Any, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
  8. Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueW" (ByVal hKey As Long, lpSubKey As Any, lpValue As Any, lpcbValue As Long) As Long
  9. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

  10. Sub GetSoftwareInfo(ByVal RegSubKey As String)
  11. On Error Resume Next
  12. Dim WScrShl As Object
  13. Set WScrShl = CreateObject("WScript.Shell")

  14. Dim RegVal As String
  15. RegVal = WScrShl.RegRead("HKLM" & RegSubKey & "\DisplayName")
  16. If Len(RegVal) Then lstSoftwares.AddItem RegVal

  17. End Sub

  18. Sub EnumAllSoftwares()
  19. Dim RegKey As Long
  20. ErrNo = RegOpenKey(HKEY_LOCAL_MACHINE, ByVal StrPtr("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"), RegKey)
  21. If ErrNo Then GoTo Cleanup

  22. Dim NbSubKeys As Long, NbValues As Long, MaxSubKeyLen As Long
  23. ErrNo = RegQueryInfoKey(RegKey, ByVal 0, ByVal 0, 0, NbSubKeys, MaxSubKeyLen, ByVal 0, NbValues, ByVal 0, ByVal 0, ByVal 0, ByVal 0)
  24. If ErrNo Then GoTo Cleanup

  25. Dim I&
  26. For I = 0 To NbSubKeys - 1
  27.     Dim SubKeyName As String
  28.     SubKeyName = String(MaxSubKeyLen, 0)
  29.     ErrNo = RegEnumKey(RegKey, I, ByVal StrPtr(SubKeyName), MaxSubKeyLen)
  30.     If ErrNo Then GoTo Cleanup
  31.     SubKeyName = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & Replace(SubKeyName, vbNullChar, "")
  32.     GetSoftwareInfo SubKeyName
  33.     If ErrNo Then GoTo Cleanup
  34. Next

  35. RegCloseKey RegKey
  36. Exit Sub
  37. Cleanup:
  38. If RegKey Then RegCloseKey RegKey
  39. MsgBox ErrNo
  40. End Sub

  41. Private Sub Form_Load()
  42. Show
  43. EnumAllSoftwares
  44. End Sub

  45. Private Sub Form_Resize()
  46. lstSoftwares.Move 0, 0, ScaleWidth, ScaleHeight
  47. End Sub
复制代码
BIN: 列出程序.exe (20 KB, 下载次数: 4)
SRC:回帖后可见。
游客,如果您要查看本帖隐藏内容请回复

本帖被以下淘专辑推荐:

回复

使用道具 举报

发表于 2020-4-3 21:44:34 | 显示全部楼层
看看学习下
回复 赞! 靠!

使用道具 举报

发表于 2020-7-8 14:31:15 | 显示全部楼层
本帖最后由 china_shy_wzb 于 2020-7-20 14:07 编辑

系统安装的所有程序
回复 赞! 靠!

使用道具 举报

发表于 2021-11-12 22:07:30 | 显示全部楼层
gggggggggggggggggggggggggggggggggggg
回复 赞! 靠!

使用道具 举报

发表于 2022-4-14 16:11:24 | 显示全部楼层
64位系统下还得读一个wow目录,不然可能会有遗漏,只要能读到和控制面板-程序里面的条目一样就行了
回复 赞! 靠!

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-11-23 17:30 , Processed in 0.039053 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表