InsaneProgrammer
Programmer
The following code extracts software information from the WMI. It works well. However, I notice in the Windows MMC there is also information on Internet Explorer. The IE information is not stored in the same place in the WMI as the other software information. I've read several articles on the WMI and even downloaded the toolkit and tutorial from Microsofts Website but I can't seem to find how to get IE info. Any help would be appreciated. Below is part of the code I use to get the software data. It gets dumped into a SQL Server. I think the code in red i where I need to make a change.
[tt]
Option Explicit
Dim cn1 As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim objWMI As Object
Dim colSoftware As Object
Dim clsSoftware As Object
Dim sCaption As String
Dim sDescription As String
Dim sID As String
Dim sInstallDate As String
Dim sLocation As String
Dim sInstallState As String
Dim sName As String
Dim sPackageCache As String
Dim sSKU As String
Dim sVendor As String
Dim sVersion As String
Private Sub cmdExecute_Click()
Dim sConn As String
Dim sSQL1 As String
Dim sSQL2 As String
MousePointer = vbHourglass
sConn = "Provider=SQLOLEDB.1;Initial Catalog=Inventory;Data Source=SQLSERVERNAME;User ID=USERID;Password=USERPASSWORD;"
With cn1
.ConnectionString = sConn
.CursorLocation = adUseClient
.Open
End With
With rs1
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenStatic
rs1.ActiveConnection = cn1
End With
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & txtComputerName & "\root\cimv2"
Set colSoftware = objWMI.ExecQuery("Select * From Win32_Product"
On Error Resume Next
'Get the installed software data
For Each clsSoftware In colSoftware
If IsNull(clsSoftware.Caption) Then
sCaption = "Unkown"
Else
sCaption = clsSoftware.Caption
End If
If IsNull(clsSoftware.Description) Then
sDescription = "Unkown"
Else
sDescription = clsSoftware.Description
End If
If IsNull(clsSoftware.IdentifyingNumber) Then
sID = "Unkown"
Else
sID = clsSoftware.IdentifyingNumber
End If
If IsNull(clsSoftware.InstallDate2) Then
sInstallDate = "Unkown"
Else
sInstallDate = clsSoftware.InstallDate2
End If
If IsNull(clsSoftware.InstallLocation) Then
sLocation = "Unkown"
Else
sLocation = clsSoftware.InstallLocation
End If
If IsNull(clsSoftware.InstallState) Then
sInstallState = "Unkown"
Else
sInstallState = clsSoftware.InstallState
End If
If IsNull(clsSoftware.Name) Then
sName = "Unkown"
Else
sName = clsSoftware.Name
End If
If IsNull(clsSoftware.PackageCache) Then
sPackageCache = "Unkown"
Else
sPackageCache = clsSoftware.PackageCache
End If
If IsNull(clsSoftware.SKUNumber) Then
sSKU = "Unkown"
Else
sSKU = clsSoftware.SKUNumber
End If
If IsNull(clsSoftware.Vendor) Then
sVendor = "Unkown"
Else
sVendor = clsSoftware.Vendor
End If
If IsNull(clsSoftware.Version) Then
sVersion = "Unkown"
Else
sVersion = clsSoftware.Version
End If
sVersion = clsSoftware.Version
sSQL1 = "select * from tblSoftware where ComputerName = '" & txtComputerName & "' and IDNumber = '" & sID & "'"
rs1.Open sSQL1
If rs1.BOF And rs1.EOF Then
sSQL2 = "insert into tblSoftware (ComputerName, Caption, Description, IDNumber, InstallDate, Location, InstallState, Name, PackageCache, SKUNumber, Vendor, Version) "
sSQL2 = sSQL2 & "values ('" & txtComputerName & "', '" & sCaption & "', '" & sDescription & "', '" & sID & "', '" & sInstallDate & "', '" & sLocation & "', '" & sInstallState & "', '" & sName & "', '" & sPackageCache & "', '" & sSKU & "', '" & sVendor & "', '" & sVersion & "')"
Else
sSQL2 = "update tblSoftwareTest set "
End If
cn1.Execute sSQL2
Next
ProgressBar1 = ProgressBar1.Max
cn1.Close
Set cn1 = Nothing
MousePointer = vbDefault
End Sub
[/tt]
[tt]
Option Explicit
Dim cn1 As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim objWMI As Object
Dim colSoftware As Object
Dim clsSoftware As Object
Dim sCaption As String
Dim sDescription As String
Dim sID As String
Dim sInstallDate As String
Dim sLocation As String
Dim sInstallState As String
Dim sName As String
Dim sPackageCache As String
Dim sSKU As String
Dim sVendor As String
Dim sVersion As String
Private Sub cmdExecute_Click()
Dim sConn As String
Dim sSQL1 As String
Dim sSQL2 As String
MousePointer = vbHourglass
sConn = "Provider=SQLOLEDB.1;Initial Catalog=Inventory;Data Source=SQLSERVERNAME;User ID=USERID;Password=USERPASSWORD;"
With cn1
.ConnectionString = sConn
.CursorLocation = adUseClient
.Open
End With
With rs1
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenStatic
rs1.ActiveConnection = cn1
End With
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & txtComputerName & "\root\cimv2"
Set colSoftware = objWMI.ExecQuery("Select * From Win32_Product"
On Error Resume Next
'Get the installed software data
For Each clsSoftware In colSoftware
If IsNull(clsSoftware.Caption) Then
sCaption = "Unkown"
Else
sCaption = clsSoftware.Caption
End If
If IsNull(clsSoftware.Description) Then
sDescription = "Unkown"
Else
sDescription = clsSoftware.Description
End If
If IsNull(clsSoftware.IdentifyingNumber) Then
sID = "Unkown"
Else
sID = clsSoftware.IdentifyingNumber
End If
If IsNull(clsSoftware.InstallDate2) Then
sInstallDate = "Unkown"
Else
sInstallDate = clsSoftware.InstallDate2
End If
If IsNull(clsSoftware.InstallLocation) Then
sLocation = "Unkown"
Else
sLocation = clsSoftware.InstallLocation
End If
If IsNull(clsSoftware.InstallState) Then
sInstallState = "Unkown"
Else
sInstallState = clsSoftware.InstallState
End If
If IsNull(clsSoftware.Name) Then
sName = "Unkown"
Else
sName = clsSoftware.Name
End If
If IsNull(clsSoftware.PackageCache) Then
sPackageCache = "Unkown"
Else
sPackageCache = clsSoftware.PackageCache
End If
If IsNull(clsSoftware.SKUNumber) Then
sSKU = "Unkown"
Else
sSKU = clsSoftware.SKUNumber
End If
If IsNull(clsSoftware.Vendor) Then
sVendor = "Unkown"
Else
sVendor = clsSoftware.Vendor
End If
If IsNull(clsSoftware.Version) Then
sVersion = "Unkown"
Else
sVersion = clsSoftware.Version
End If
sVersion = clsSoftware.Version
sSQL1 = "select * from tblSoftware where ComputerName = '" & txtComputerName & "' and IDNumber = '" & sID & "'"
rs1.Open sSQL1
If rs1.BOF And rs1.EOF Then
sSQL2 = "insert into tblSoftware (ComputerName, Caption, Description, IDNumber, InstallDate, Location, InstallState, Name, PackageCache, SKUNumber, Vendor, Version) "
sSQL2 = sSQL2 & "values ('" & txtComputerName & "', '" & sCaption & "', '" & sDescription & "', '" & sID & "', '" & sInstallDate & "', '" & sLocation & "', '" & sInstallState & "', '" & sName & "', '" & sPackageCache & "', '" & sSKU & "', '" & sVendor & "', '" & sVersion & "')"
Else
sSQL2 = "update tblSoftwareTest set "
End If
cn1.Execute sSQL2
Next
ProgressBar1 = ProgressBar1.Max
cn1.Close
Set cn1 = Nothing
MousePointer = vbDefault
End Sub
[/tt]