Installed Software List on Remote Machine using Registry

Public Sub SoftwareInformationRegistry(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String)

        Dim objLocator, objService, objRegistry, arrIdentityCode, strIdentityCode, objShell
        Dim objFSO, objTextFile
        Dim strRegIdentityCodes As String

        objLocator = CreateObject("WbemScripting.SWbemLocator")


        Try

            If (strComputer = System.Environment.MachineName) Then

                objService = objLocator.ConnectServer(strComputer, "Root\Default")
            Else
                objService = objLocator.ConnectServer(strComputer, "Root\Default", strUserName, strPwd)
            End If

            objService.Security_.impersonationlevel = 3

            objRegistry = objService.Get("StdRegProv")

        Catch ex As Exception

            MessageBox.Show("Kindly Enter Domain Credential.", "Remote Software Install", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub

        End Try


        strRegIdentityCodes = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"


        Const HKLM = &H80000002
        Const APPEND = 8

        Dim strRegIdentityInfo, strDisplayName, strDisplayVersion, strInstallDate, strUninstallString, strPublisher

        objRegistry.EnumKey(HKLM, strRegIdentityCodes, arrIdentityCode)
        objShell = CreateObject("WScript.Shell")

        Dim strName As String

        objFSO = CreateObject("Scripting.FileSystemObject")
        objTextFile = objFSO.CreateTextFile("c:\software.txt", True)
        objTextFile.WriteLine("Name" & vbTab & _
                        "Version" & vbTab & "Install Date" & vbTab & _
                        "UninstallString" & vbTab & "Publisher")

        For Each strIdentityCode In arrIdentityCode

            Try

                strRegIdentityInfo = "HKEY_LOCAL_MACHINE\" & strRegIdentityCodes & "\" & strIdentityCode & "\"
                strDisplayName = objShell.RegRead(strRegIdentityInfo & "DisplayName")
                strDisplayVersion = objShell.RegRead(strRegIdentityInfo & "DisplayVersion")
                strInstallDate = InstallDate(objShell.RegRead(strRegIdentityInfo & "InstallDate"))
                strUninstallString = objShell.RegRead(strRegIdentityInfo & "UninstallString")
                strPublisher = objShell.RegRead(strRegIdentityInfo & "Publisher")

                strName = strDisplayName

                If (strName.StartsWith("Hotfix") Or strName.StartsWith("Security") Or strName.StartsWith("Update")) Then

                Else

                    objTextFile.WriteLine(strDisplayName & vbTab & strDisplayVersion & vbTab & strInstallDate & vbTab & strUninstallString & vbTab & strPublisher)

                End If

                strDisplayName = ""
                strDisplayVersion = ""
                strInstallDate = ""
                strUninstallString = ""
                strPublisher = ""

            Catch ex As Exception

                Continue For
            End Try

        Next

End Sub

Private Function InstallDate(ByVal strDate As String) As String

        Try

            Dim YY, MM, DD As String

            YY = strDate.Substring(0, 4)
            MM = strDate.Substring(4, 2)
            DD = strDate.Substring(6, 2)

            Return DD & "-" & MM & "-" & YY

        Catch ex As Exception

        End Try

End Function

Related Posts by Categories



Stumble This Fav This With Technorati Add To Del.icio.us Digg This Add To Reddit Add To Facebook Add To Yahoo

0 comments:

Post a Comment