VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,474 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,720 people online right now. Registration is fast and FREE... Join Now!




write a code to list out the installed software

 

write a code to list out the installed software

avinashb87

21 Jul, 2008 - 08: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
+Quote Post


Jayman

RE: Write A Code To List Out The Installed Software

22 Jul, 2008 - 06:40 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,544



Thanked: 226 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Moved to VB.NET.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Write A Code To List Out The Installed Software

22 Jul, 2008 - 10:24 PM
Post #3

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

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 offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Write A Code To List Out The Installed Software

23 Jul, 2008 - 12:58 PM
Post #4

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,686



Thanked: 155 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

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
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:57AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month