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 **