Installierte Anwendungen aufliesten

    • VB.NET

      Installierte Anwendungen aufliesten

      VB.NET-Quellcode

      1. 'Beispiel: VB .Net - Registrierdatenbank - Installierte Software ermitteln
      2. '
      3. Option Explicit On
      4. Option Strict On
      5. Imports Microsoft.Win32
      6. Imports Microsoft.VisualBasic.ControlChars
      7. Imports System.Globalization
      8. Public Class Form1
      9. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      10. Handles Button1.Click
      11. GetInstalledSoftware(My.Computer.Name)
      12. End Sub
      13. Private Sub GetInstalledSoftware(ByVal machineName As String)
      14. Dim hKey As RegistryKey
      15. Dim SubKey As RegistryKey
      16. Dim Path As String = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
      17. Dim Items As String()
      18. Dim DisplayName As String
      19. Dim InstallSource As String
      20. Dim InstallDate As String
      21. Try
      22. hKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName)
      23. SubKey = hKey.CreateSubKey(Path)
      24. Items = SubKey.GetSubKeyNames()
      25. For n As Integer = 0 To Items.Length - 1
      26. Dim rk As RegistryKey = SubKey.OpenSubKey(Items(n), False)
      27. Try
      28. DisplayName = (rk.GetValue("DisplayName").ToString())
      29. InstallDate = (rk.GetValue("InstallDate").ToString())
      30. InstallSource = (rk.GetValue("InstallSource").ToString())
      31. Me.ListBox1.Items.Add(DisplayName & Tab & Tab & ConvertStringToDate(InstallDate) & _
      32. Tab & Tab & InstallSource)
      33. Catch
      34. End Try
      35. Next
      36. hKey.Close()
      37. Catch ex As Exception
      38. End Try
      39. End Sub
      40. Private Function ConvertStringToDate(ByVal s As String) As String
      41. Try
      42. Dim k As Integer = s.IndexOf(".")
      43. Dim j As Integer = s.IndexOf("/")
      44. Dim i As Integer = s.IndexOf("\")
      45. Dim n As Integer = s.IndexOf(":")
      46. Const DateLength As Integer = 8
      47. If k > -1 Or j > -1 Or i > -1 Or n > -1 Then
      48. Return s
      49. Else
      50. If s.Length = DateLength Then
      51. Dim Result As String = s.Substring(0, 4) & "/" & s.Substring(4, 2) & "/" & _
      52. s.Substring(6, 2)
      53. Dim ci As CultureInfo = CultureInfo.InvariantCulture
      54. Dim dt As DateTime = DateTime.ParseExact(Result, "yyyy/MM/dd", _
      55. ci, DateTimeStyles.NoCurrentDateDefault)
      56. Return dt.ToShortDateString()
      57. Else
      58. End If
      59. End If
      60. Catch ex As Exception
      61. Return "-"
      62. End Try
      63. Return ""
      64. End Function
      65. Private Sub ListBoxInitTabStops(ByRef lb As System.Windows.Forms.ListBox)
      66. Try
      67. If (Not lb Is Nothing) Then
      68. Dim cntTabs() As Integer = {200, 210, 220}
      69. Call Win32Api.SendMessage(lb.Handle, Win32Api.LB_SETTABSTOPS, _
      70. cntTabs.Length, cntTabs(0))
      71. End If
      72. Catch ex As Exception
      73. MessageBox.Show(ex.Message.ToString(), "Info")
      74. End Try
      75. End Sub
      76. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      77. Handles MyBase.Load
      78. Call ListBoxInitTabStops(ListBox1)
      79. End Sub
      80. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      81. Handles Button2.Click
      82. GetInstalledSoftwareExeFiles(My.Computer.Name)
      83. End Sub
      84. Private Sub GetInstalledSoftwareExeFiles(ByVal machineName As String)
      85. Dim hKey As RegistryKey
      86. Dim SubKey As RegistryKey
      87. Dim Path As String = "Software\Microsoft\Windows\CurrentVersion\App Paths"
      88. Dim Items As String()
      89. Dim exePath As String
      90. Try
      91. hKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName)
      92. SubKey = hKey.CreateSubKey(Path)
      93. Items = SubKey.GetSubKeyNames()
      94. For n As Integer = 0 To Items.Length - 1
      95. Dim rk As RegistryKey = SubKey.OpenSubKey(Items(n), False)
      96. Try
      97. exePath = (rk.GetValue("").ToString())
      98. If exePath.IndexOf(Quote) > -1 Then exePath = exePath.Replace(Quote, "")
      99. If exePath.LastIndexOf(Quote) > -1 Then exePath = exePath.Replace(Quote, "")
      100. Dim Root As String = IO.Path.GetPathRoot(exePath)
      101. If DirectoryExists(Root) = True Then
      102. If IO.File.Exists(exePath) Then
      103. Me.ListBox2.Items.Add(exePath.ToLower())
      104. Else
      105. Debug.WriteLine(exePath)
      106. End If
      107. Else
      108. Debug.WriteLine(exePath)
      109. End If
      110. Catch
      111. End Try
      112. Next
      113. hKey.Close()
      114. Catch ex As Exception
      115. End Try
      116. End Sub
      117. Private Function DirectoryExists(ByVal Root As String) As Boolean
      118. Try
      119. Dim files() As String = IO.Directory.GetFiles(Root, "*.*")
      120. If files.Length < 1 Then
      121. Return False
      122. Else
      123. Return True
      124. End If
      125. Catch
      126. Return False
      127. End Try
      128. End Function
      129. Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
      130. Handles ListBox2.SelectedIndexChanged
      131. Try
      132. Dim psi As New ProcessStartInfo()
      133. With psi
      134. .ErrorDialog = True
      135. .FileName = CStr(ListBox2.SelectedItem)
      136. .UseShellExecute = True
      137. End With
      138. Process.Start(psi)
      139. Catch
      140. End Try
      141. End Sub
      142. End Class
      143. Public Module Win32Api
      144. #Region "Required Windows Application Interface"
      145. <Runtime.InteropServices.DllImport("user32.dll")> _
      146. Public Sub SendMessage( _
      147. ByVal hWnd As IntPtr, _
      148. ByVal uMsg As Int32, _
      149. ByVal wParam As Int32, _
      150. ByRef lParam As Int32)
      151. End Sub
      152. #End Region
      153. #Region "Required Windows Constants"
      154. Public Const LB_SETTABSTOPS As Int32 = &H192
      155. #End Region
      156. End Module



      link zu Code


      Mfg Alex