Dim strComputerName ' The Computer Name to be queried via WMI
Dim strWinMgt ' The WMI management String
Dim objCon ' A Connection Object for database connectivity
Dim objRS ' A Recordset Object for database connectivity
Dim sProviderName ' The OLE Provider Type
Dim iCursorType ' The Cursor Type for the Recordset
Dim iLockType ' The Lock Type for the Recordset
Dim sDataSource ' The name and location of the database
Dim intCompID ' A computer ID asssigned when the computer is added to the database
Dim intRam ' The amount of RAM in the computer.
'
' Get the Computer Name to Collect Information For
'
strComputerName = InputBox("Enter the name of the computer you wish to query"

strWinMgt = "winmgmts://" & strComputerName &""
'
' Write Computer Info to Database
'
call subConnectionOpen
call subWriteComputerInfo
call subWriteDiskInfo
call subWriteIPInfo
call subWriteSoftwareInfo
call subConnectionClose
wscript.echo "Finished Collection Information for the System."
Sub subConnectionOpen
Set objCon = CreateObject("ADODB.Connection"

Set objRS = CreateObject("ADODB.Recordset"

sProviderName = "Microsoft.Jet.OLEDB.4.0"
iCursorType = 1
iLockType = 3
sDataSource = "\\d01svr67\desktop\jeff_tools\wmi_database_current\dbassets.mdb"
objCon.Provider = sProviderName
objCon.Properties("Data Source"

= sDataSource
objCon.Open
End Sub
Sub subConnectionClose
set objRS = nothing
set objCon = nothing
End Sub
Sub subWriteComputerInfo
Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem"

for each CompSys in CompSysSet
strDescription = CompSys.Description
strModel = CompSys.Model
strName = CompSys.Name
intRAM = Clng(CompSys.TotalPhysicalMemory/1000000)
next
objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblComputer"
objRS.ActiveConnection = objCon
objRS.Open
objRS.AddNew
objRS("strName"

= strName
objRS("strModel"

= strModel
objRS("strDescription"

= strDescription
objRS.Update
intCompID = objRS("ID"

objRS.Close
objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblMemory"
objRS.ActiveConnection = objCon
objRS.Open
objRS.AddNew
objRS("intCompID"

= intCompID
objRS("intRAM"

= intRam
objRS.Update
objRS.Close
End Sub
Sub subWriteDiskInfo
'
' Get Disk Information
'
Set DiskSet = GetObject(strWinMgt).ExecQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3"

objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblDisk"
objRS.ActiveConnection = objCon
objRS.Open
For each Disk in DiskSet
strDisplayDiskInfo = strDisplayDiskInfo & "Drive " & Disk.Name & " Free Space: " & Clng(Disk.FreeSpace/1000000) & " MB Total Size: " & Clng(Disk.Size/1000000) & " MB"& vbCrlf
if len(Left(disk.name,1)) >0 then
objRS.AddNew
objRS("intCompID"

= intCompID
objRS("strDriveLetter"

= Left(disk.name,1)
objRS("strFreeSpace"

= Clng(Disk.FreeSpace/1000000)
objRS("strTotalSpace"

= Clng(Disk.Size/1000000)
objRS.Update
end if
Next
objRS.Close
' Wscript.echo strDisplayDiskInfo
End Sub
Sub subWriteIPInfo
set IPConfigSet = GetObject(strWinMgt).ExecQuery("select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"

objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblIPInfo"
objRS.ActiveConnection = objCon
objRS.Open
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
' WScript.Echo "IPAddress: " & IPConfig.IPAddress(i) & " Subnet: " &_
' IPConfig.IPSubnet(i) & "MAC Address " & IPConfig.MACAddress
objRS.AddNew
objRS("intCompID"

= intCompID
objRS("intNICID"

= i
objRS("txtIPAddress"

= IPConfig.IPAddress(i)
objRS("txtSubnetMask"

= IPConfig.IPSubnet(i)
objRS("txtMACAddress"

= IPConfig.MACAddress
objRS("txtServiceName"

= IPConfig.ServiceName
objRS("txtDescription"

= IPConfig.Description
objRS.Update
next
end if
next
objRS.Close
End sub
Sub subWriteSoftwareInfo
Dim rsPackage, sSQL, iPackageID
set colItems = GetObject(strWinMgt).ExecQuery("select * from Win32_Product"
for Each objItem In colItems
sSQL = "SELECT * FROM tblPackage WHERE txtName = '" & objItem.Name & "'"
sSQL = sSQL & " AND txtVendor = '" & objItem.Vendor & "'"
sSQL = sSQL & " AND txtVersion = '" & objItem.Version & "'"
Set rsPackage = objCon.Execute(sSQL)
If rsPackage.EOF Then
sSQL = "INSERT INTO tblPackage (txtCaption,txtDescription,txtName,txtVendor,txtVersion) "
sSQL = sSQL & " VALUES ('" & objItem.Caption & "','" & objItem.Description & "','" & objItem.Name & "','" & objItem.Vendor & "','" & objItem.Version & "')"
objCon.Execute sSQL
sSQL = "SELECT max(intPackageID) As intPackageID FROM tblPackage"
Set rsPackage = objCon.Execute(sSQL)
iPackageID = rsPackage("intPackageID"

Else
iPackageID = rsPackage("intPackageID"

End If
sSQL = "INSERT INTO tblComputerPackage(intCompID, intPackageID) VALUES (" & intCompID & "," & iPackageID & "

"
objCon.Execute sSQL
Next
rsPackage.Close
End Sub