|
Here is my current code!
Dim strStatus
Dim pstatus
Dim IE
Dim Connect
Dim objWMIService, objSystem, a
Dim ColSystem, sManufacturer, sSystemtype, sSystemName, sBiosRev
Dim sServiceTag, sAssetTag, subnet
On Error Resume Next
'===================
'| Create IE Object
'===================
Set objCDO = wscript.CreateObject("CDO.Message")
Set objExplorer = WScript.CreateObject("InternetExplorer.Application ", "IE_")
objExplorer.Navigate ""
objExplorer.Visible = 1
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=600
objExplorer.Height = 600
objExplorer.Left = 0
objExplorer.Top = 0
Wscript.Sleep 250
subnet = inputbox("enter system To scan:" & vbCrlf & "Example: 140.171.99.")
If subnet = "" Then
subnet = "."
End If
If subnet = "." Then
Call getinfo(subnet)
Else
For n = 1 To 255
Call pingcheck(subnet & n)
Next
End If
Call updatestatus("Complete")
wscript.sleep 1000
If objExplorer.Document.Body.All.wclose.checked Then
objExplorer.quit
End If
Function Updatestatus(comments)
objExplorer.Document.Body.All.wstatus.Value = comments
'wscript.sleep 500
End Function
Function pingcheck(IPAddress)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery("select * from Win32_PingStatus where address = '" & IPAddress & "'")
Call updatestatus("Pinging " & ipaddress)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
Else
Call getinfo(IPAddress)
End If
Next
End Function
'================================================= ================================================== =
Function GetInfo(IPAddress)
'On Error Resume Next
While objExplorer.busy
wscript.sleep 50
Wend
'================================================= =========================
' Declare Variables
'================================================= =========================
Set conn = WScript.CreateObject("ADODB.Connection")
Connect="Driver={SQL Server};Server=;Database=;UID=;PWD="
conn.Open connect
Call updatestatus("Searching " & ipaddress)
' Connect to remote system. If system is powered off, it may take up To
' 45 seconds for the connection attempt to time out
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e,AuthenticationLevel=pktprivacy}\\" & IPAddress & "\root\cimv2")
If Err.Number = 0 Then
' If able to connect gather data from CimV2 namespace
Set ColSystem=objWMIService.execquery ("Select * from Win32_ComputerSystem")
Call updatestatus("Searching hardware")
For each objSystem in colSystem
sManufacturer = objSystem.Manufacturer
sSystemtype = objSystem.Model
sSystemName = objSystem.Name
Next
Set ColSystem=objWMIService.execquery ("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Call updatestatus("Searching Network Card")
For Each objAdapter In ColSystem
If Not IsNull(objAdapter.IPAddress) Then
sIPAddress = objAdapter.IPAddress(0)
sMacAddress = objAdapter.MacAddress
objExplorer.Document.Body.All.wIPAddress.Value = sIPAddress
End If
Next
' Set ColSystem=objWMIService.execquery ("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
' Call updatestatus("Searching hardware")
' sIPAddress = objAdapter.IPAddress
'msgbox sipaddress
sql1 = "SELECT * FROM tblinv where fldsystemname='" & sSystemName & "'"
Set rs1 = WScript.CreateObject("ADODB.Recordset")
rs1.open sql1, conn, 3, 3
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_Product")
Call updatestatus("Searching for installed software")
If rs1.recordcount > 0 Then
If datediff("d",rs1.fields("fldinvdate"),now()) > 60 Then
saction = "update"
Else
saction = "none"
End If
Else
saction = "add"
End If
Select Case saction
Case "none"
Case Else
For Each objSystem In colSystem
objExplorer.Document.Body.All.wsoftware.value = objExplorer.Document.Body.All.wsoftware.value & vbCrlf & objsystem.name
Select Case saction
Case "add"
rs1.addnew
rs1.fields("fldsystemname")= sSystemName
rs1.fields("fldsoftware")= objSystem.Name
rs1.fields("fldinvdate")=Now()
rs1.update
Case "update"
rs1.close
Call updatestatus("Removing Old Records From Database")
sql1 = "DELETE FROM tblinv where fldsystemname='" & sSystemName & "'"
rs1.open sql1, conn, 3, 3
rs1.close
sql1 = "SELECT * FROM tblinv where fldsystemname='" & sSystemName & "'"
rs1.open sql1, conn, 3, 3
rs1.addnew
rs1.fields("fldsystemname")= sSystemName
rs1.fields("fldsoftware")= objSystem.Name
rs1.fields("fldinvdate")=Now()
rs1.update
saction = "add"
Case Else
End Select
Next
End Select
rs1.close
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_BIOS")
Call updatestatus("Searching BIOS")
For each objSystem in colSystem
sBiosRev = objSystem.SMBIOSBIOSVersion
Next
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_processor")
Call updatestatus("Searching CPU SPeed")
For Each objSystem In colSystem
cp = cp + 1
sclockspeed = objSystem.currentclockspeed
Next
objExplorer.Document.Body.All.wcpucount.Value = cp
'Set colSystem=objWMIService.ExecQuery _
' ("Select * from Win32_temperatureprobe")
' For Each objSystem In colSystem
' stemperature = objSystem.CurrentReading
' Next
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_operatingsystem")
Call updatestatus("Determining Operating System")
For Each objSystem In colSystem
scaption = objSystem.caption
Next
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_physicalmemory")
Call updatestatus("Determining Memory Installed")
For Each objSystem In colSystem
scapacity = scapacity + cint((objSystem.capacity/1048576))
Next
' Set colSystem=objWMIService.ExecQuery _
' ("Select * from Win32_userAccount.domain=vssi,user=administrator")
'For Each objSystem In colSystem
' sdomain = sdomain & vbCrlf & objsystem.domain
' suser = objsystem.name
'Next
'msgbox sdomain
Set colSystem=objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure")
Call updatestatus("Determining Serial & Asset Tag #")
For each objSystem in colSystem
sServiceTag = objSystem.serialNumber
sAssetTag = objSystem.SmBiosAssetTag
Next
objExplorer.Document.Body.All.wIPAddress.Value = sIPAddress
objExplorer.Document.Body.All.wBiosRev.Value = sBiosrev
objExplorer.Document.Body.All.wSystemType.Value = ssystemtype
objExplorer.Document.Body.All.wSystemName.Value = ssystemname
objExplorer.Document.Body.All.wServiceTag.Value = sservicetag
objExplorer.Document.Body.All.wManufacturer.Value = smanufacturer
objExplorer.Document.Body.All.wclockspeed.Value = sclockspeed
objExplorer.Document.Body.All.wcaption.Value = scaption
objExplorer.Document.Body.All.wcapacity.Value = scapacity
objExplorer.Document.Body.All.wfullname.Value = sfullname
objExplorer.Document.Body.All.wuser.Value = suser
'============================
'| Create Database connection
'============================
Set rs = WScript.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM datacollection where (flddstn='" & sservicetag & "')"
rs.Open sql, conn, 3, 3
Call updatestatus("Writing Information to database")
If rs.recordcount > 0 Then
rs.fields("fldipaddress") = sIPAddress
rs.fields("fldbiosrev") = sBiosrev
rs.fields("fldmodel") = ssystemtype
rs.fields("fldNodeName") = ssystemname
' rs.fields("flddstn") = sservicetag
rs.fields("fldmanufacturer") = smanufacturer
rs.fields("fldcpuspeed") = sclockspeed
rs.fields("fldOS") = scaption
rs.fields("fldmem") = scapacity
rs.fields("fldcpuqty") = cp
rs.fields("meetsmin") = "True"
rs.fields("macadd") = smacaddress
' rs.fields("fldfullname") = sfullname
' rs.fields("flduser") = suser
rs.update
rs.close
Else
rs.addnew
rs.fields("fldipaddress") = sIPAddress
rs.fields("fldbiosrev") = sBiosrev
rs.fields("fldmodel") = ssystemtype
rs.fields("fldNodeName") = ssystemname
rs.fields("flddstn") = sservicetag
rs.fields("fldmanufacturer") = smanufacturer
rs.fields("fldcpuspeed") = sclockspeed
rs.fields("fldOS") = scaption
rs.fields("fldmem") = scapacity
rs.fields("fldcpuqty") = cp
rs.fields("meetsmin") = "True"
' rs.fields("fldfullname") = sfullname
' rs.fields("flduser") = suser
rs.update
rs.close
End If
Else
' If errors, then return string stating could not connect to system with error description
objExplorer.Document.Body.All.werror.Value = Err.description
Err.clear
End If
End Function
|