Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 105,772 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,387 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



write a code to list out the installed software

 
Reply to this topicStart new topic

write a code to list out the installed software

avinashb87
post 21 Jul, 2008 - 09:54 PM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 5

hi viewers.

when i build the project no errors occured,
but at run time the error occured at :


vb

wscript.echo("Debut")-------> ststing "NullReference exception was unhandled "




Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strComputer = "."



Dim fs
Dim fictxt




fs = CreateObject("Scripting.FileSystemObject")
fictxt = fs.opentextfile("C:\asoftware.txt", 2, True)

Const BASE_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Const HKLM = &H80000002
Dim strDisplayName
Dim strDisplayVersion
Dim strInstallLocation
Dim strDisplayVersionMajor
Dim strDisplayVersionMinor
Dim strInstallDate
Dim strInstallFrom
Dim lngRtn
Dim astrSubKeys
Dim strKey
Dim vntTmp
Dim debTitre
Dim indiceLg
Dim isnull
Dim strCaption
Dim strDesc
Dim strId
Dim strInstLoc
Dim strName
Dim strPC
Dim strVendor
Dim strVersion
Dim objWMIService
Dim wscript


wscript.echo("Debut")

Dim j
Dim colsoftware
Dim objsoftware

ReDim vntTmp(5)

debTitre = indiceLg
indiceLg = indiceLg + 2

On Error Resume Next
Err.Clear()

colsoftware = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select * from Win32_Product")

If Err.Number <> 0 Then
fictxt.writeline("Connexion error " & strComputer)
On Error GoTo 0
Else
On Error GoTo 0

For Each objsoftware In colsoftware

If Not (isnull(objsoftware.Caption)) Then strCaption = objsoftware.Caption Else strCaption = ""
If Not (isnull(objsoftware.Description)) Then strDesc = objsoftware.Description Else strDesc = ""
If Not (isnull(objsoftware.IdentifyingNumber)) Then strId = objsoftware.IdentifyingNumber Else strId = ""
If Not (isnull(objsoftware.InstallDate)) Then strInstallDate = objsoftware.InstallDate Else strInstallDate = ""
If Not (isnull(objsoftware.InstallLocation)) Then strInstLoc = objsoftware.InstallLocation Else strInstLoc = ""
If Not (isnull(objsoftware.Name)) Then strName = objsoftware.Name Else strName = ""
If Not (isnull(objsoftware.PackageCache)) Then strPC = objsoftware.PackageCache Else strPC = ""
If Not (isnull(objsoftware.Vendor)) Then strVendor = objsoftware.Vendor Else strVendor = ""
If Not (isnull(objsoftware.Version)) Then strVersion = objsoftware.Version Else strVersion = ""


fictxt.writeline(strCaption & Space(60 - Len(strCaption)) & _
strDesc & Space(60 - Len(strDesc)) & _
strId & Space(50 - Len(strId)) & _
strInstallDate & Space(25 - Len(strInstallDate)) & _
strInstLoc & Space(70 - Len(strInstLoc)) & _
strName & Space(70 - Len(strName)) & _
strPC & Space(40 - Len(strPC)) & _
strVendor & Space(35 - Len(strVendor)) & _
strVersion & Space(25 - Len(strVersion)))


Next

End If



'**************** Registry ***********************

fictxt.writeline(vbCrLf & "--------------" & vbCrLf)

On Error Resume Next
Err.Clear()

colsoftware = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "/root/default:StdRegProv")

lngRtn = colsoftware.EnumKey(HKLM, BASE_KEY, astrSubKeys)

If Err.Number <> 0 Then
fictxt.writeline("Connexion error " & strComputer)
On Error GoTo 0
Else
On Error GoTo 0

For Each strKey In astrSubKeys

strDisplayName = vbNullString
strDisplayVersion = vbNullString
strInstallLocation = vbNullString
strDisplayVersionMajor = vbNullString
strDisplayVersionMinor = vbNullString
strInstallDate = vbNullString
strInstallFrom = vbNullString

' ---------------------------------------
' Get the display name
' ---------------------------------------
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "DisplayName", strDisplayName)

' If blank, try "Quiet Name
If Trim(strDisplayName) = vbNullString Then
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "QuietDisplayName", strDisplayName)
End If

' If other 2 fail, use the key name
If Trim(strDisplayName) = vbNullString Then
strDisplayName = strKey
End If

If isnull(strDisplayName) Then vntTmp(1) = "" Else vntTmp(1) = strDisplayName

' ---------------------------------------
' Get the Display version or alternate
' ---------------------------------------
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "DisplayVersion", strDisplayVersion)

' Else, concatenate the version info
If Trim(strDisplayVersion) = vbNullString Then
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "VersionMajor", strDisplayVersionMajor)
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "VersionMinor", strDisplayVersionMinor)
strDisplayVersion = strDisplayVersionMajor & "." & strDisplayVersionMinor
End If

' If all else fails, try just the "Version" string
If Trim(strDisplayVersionMajor) = vbNullString Then
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "Version", strDisplayVersion)
End If

If isnull(strDisplayVersion) Then vntTmp(2) = "" Else vntTmp(2) = strDisplayVersion

' ---------------------------------------
' Get the installatin location
' ---------------------------------------
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "InstallLocation", strInstallLocation)

If Trim(strInstallLocation) = vbNullString Then
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "UninstallString", strInstallLocation)
End If

If isnull(strInstallLocation) Then vntTmp(3) = "" Else vntTmp(3) = strInstallLocation

' ---------------------------------------
' Get the installation Date
' ---------------------------------------
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "InstallDate", strInstallDate)

If Len(Trim(strInstallDate)) > 0 Then
If isnull(strInstallDate) Then vntTmp(4) = "" Else vntTmp(4) = strInstallDate
End If

' ---------------------------------------
' Get the install-from location
' ---------------------------------------
lngRtn = colsoftware.GetStringValue(HKLM, BASE_KEY & strKey, "InstallSource", strInstallFrom)
If isnull(strInstallFrom) Then vntTmp(5) = "" Else vntTmp(5) = strInstallFrom

' ---------------------------------------
' Export Excel
' ---------------------------------------
If Trim(vntTmp(1)) <> vbNullString And InStr(vntTmp(1), "{") = 0 Then
fictxt.writeline(vntTmp(1) & Space(100 - Len(vntTmp(1))) & _
vntTmp(4) & Space(80 - Len(vntTmp(4))) & _
vntTmp(3) & Space(110 - Len(vntTmp(3))) & _
vntTmp(5) & Space(80 - Len(vntTmp(5))) & _
vntTmp(2) & Space(80 - Len(vntTmp(2))))

End If

Next

End If


colsoftware = Nothing
objWMIService = Nothing

fictxt.close()

fictxt = Nothing
fs = Nothing


wscript.echo("fin")


End Sub
End Class


** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page


jayman9
post 22 Jul, 2008 - 07:40 PM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,241



Thanked 21 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Moved to VB.NET.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 22 Jul, 2008 - 11:24 PM
Post #3


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,031



Thanked 47 times

Dream Kudos: 7600

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI

My Contributions


You have posted this same exact topic/code in so many different forums. Are you having an issue with the code?
User is online!Profile CardPM

Go to the top of the page

AdamSpeight2008
post 23 Jul, 2008 - 01:58 PM
Post #4


D.I.C Regular

Group Icon
Joined: 29 May, 2008
Posts: 476



Thanked 31 times

Dream Kudos: 1850
My Contributions


No wonder you are getting problem you've force it to ignore errors
Snippet of your code.
vb

On Error Resume Next
Err.Clear()


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 03:55PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month