获取已安装的程序列表32位和64位程序

时间:2014-12-23 10:01:28

标签: vb6 registry 64-bit 32bit-64bit

以下是我的完整代码,其中包含安装在PC上的程序列表。但是当应用程序在64位PC上运行时,由于注册表重定向,“SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall \”注册表将自动引用“SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Uninstall”。但我想在PC上安装所有程序。所以我认为我必须访问64位和32位蜂巢。那么如何才能访问所有已安装程序的64位配置单元和32位,还是有其他技巧可以获得相同的功能吗?以下是我现有的代码。

Option Explicit


Dim StrComputer As String
Dim sCompName As String

Dim sFileName As String

Function GetAddRemove(sComp)
  'Function credit to Torgeir Bakken
  Dim cnt, oReg, sBaseKey, iRC, aSubKeys
  Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
  Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
              sComp & "/root/default:StdRegProv")
  sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
  iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)

  Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay

  For Each sKey In aSubKeys
    iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)
    If iRC <> 0 Then
      oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
    End If
    If sValue <> "" Then
      iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
                                "DisplayVersion", sVersion)
      If sVersion <> "" Then
        sValue = sValue & ",Ver: " & sVersion
      Else
        sValue = sValue
      End If
      sTmp = sTmp & sValue & vbCrLf
    cnt = cnt + 1
    End If
  Next
  sTmp = BubbleSort(sTmp)
  GetAddRemove = "INSTALLED SOFTWARE (" & cnt & ") - " & sCompName & _
                 " - " & Now() & vbCrLf & vbCrLf & sTmp
End Function

Function BubbleSort(sTmp)
  'cheapo bubble sort
  Dim aTmp, i, j, temp
  aTmp = Split(sTmp, vbCrLf)
  For i = UBound(aTmp) - 1 To 0 Step -1
    For j = 0 To i - 1
      If LCase(aTmp(j)) > LCase(aTmp(j + 1)) Then
        temp = aTmp(j + 1)
        aTmp(j + 1) = aTmp(j)
        aTmp(j) = temp
      End If
    Next
  Next
  BubbleSort = Join(aTmp, vbCrLf)
End Function

Function WriteFile(sData, sFileName)
 Dim intFile As Integer
  Dim strFile As String
  strFile = sFileName
  intFile = FreeFile
  Open strFile For Output As #intFile
    Print #intFile, sData
  Close #intFile
End Function

Private Sub Form_Load()
StrComputer = "."
sFileName = "D:\desktop\ins.txt"
Dim s As String
s = GetAddRemove(".")
Call WriteFile(s, sFileName)
End Sub

1 个答案:

答案 0 :(得分:0)

请参阅DONT_VIRTUALIZE

C:\Users\User>reg flags /?

REG FLAGS KeyName [QUERY |
                   SET [DONT_VIRTUALIZE] [DONT_SILENT_FAIL] [RECURSE_FLAG]]

  Keyname    "HKLM\Software"[\SubKey] (Restricted to these keys on
        local machine only).
    SubKey   The full name of a registry key under HKLM\Software.
  DONT_VIRTUALIZE DONT_SILENT_FAIL RECURSE_FLAG
    Used with SET; flags specified on the command line will be set,
        while those not specified will be cleared.

Examples:

  REG FLAGS HKLM\Software\MyCo\MyApp QUERY
    Displays the current flags of the key MyApp.

  REG FLAGS HKLM\Software\MyCo\MyApp SET DONT_VIRTUALIZE /s
    Sets the DONT_VIRTUALIZE flag (and clears DONT_SILENT_FAIL and
    RECURSE_FLAG) on MyApp and all its subkeys

开始 - 所有程序 - 附件 - 右键单击​​“命令提示符”,然后选择“以管理员身份运行”。键入(或通过右键单击“命令提示符”窗口并选择“粘贴”进行复制和粘贴)。表格格式的类型

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable

或表格格式

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform

它将在桌面上创建一个html文件。

请注意

这不是完整列表。这只是与Windows Installer一起安装的产品。一切都没有特色。

但正如我在上一篇文章中所述,几乎所有内容都列在注册表中。

所以要在命令提示符下看到它

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s

或在文件中

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"

以不同的格式在记事本中查看

单击开始 - 所有程序 - 附件 - 右键单击​​命令提示符,然后选择以管理员身份运行。键入Regedit并导航到

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

右键单击“卸载”键,然后选择“导出”。如果您保存为reg文件(还有文本文件,它们的文本格式略有不同),您需要右键单击该文件并选择“编辑”进行查看。

查看 Windows更新

wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe  get /format:htable