Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Either BOF or EOF is True

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
I keep getting the Either BOF or EOF is True error on line 74 in the script.

Background: i have a script that runs when loging in to the domain, the scripts runs an inventory of the computer with wmi. And i want these data from the wmi query to be added to a sql database.

The first part in the script that writes with "objRS" works greate. But when it comes to objRS2 i get the EOF error. The data from objRS2 should be inserted in to another table but be linked to the first table. The idea is to get info about computer 1 and be able to se all nic to that computer and also some extra things.

The db looks like this.
db name: inventDB
table for objRS data, name: inventTB
in the table i have columns that correspond to the script for objRS data, i also got a column named compID that is the primary key for that table

table for objRS2 data, name: inventNIC
in the table i have columns that correspond to the script for objRS2 data, i also got a column named compID that is linked to the primary key in table inventTB. (table inventNIC dosent contain a primary key if that mathers?)


The code looks like this.
Code:
'On Error Resume Next

Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")


	Set objNetwork = CreateObject("WScript.Network")
	strComputer = objNetwork.ComputerName

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")

objConn.Open "DSN=inventcon;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM inventTB" , objConn, 3, 3


Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &"\root\default:StdRegProv")

Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

For Each objItem in colItems
    objRS.AddNew
    objRS("Caption") = objItem.Caption
    objRS("Description") = objItem.Description
    objRS("InstallDate") = objItem.InstallDate
    objRS("Organization") = objItem.Organization
    objRS("OSProductSuite") = objItem.OSProductSuite
    objRS("RegisteredUser") = objItem.RegisteredUser
    objRS("ServicePackMajorVersion") = objItem.ServicePackMajorVersion
    objRS("ServicePackMinorVersion") = objItem.ServicePackMinorVersion
    objRS("Version") = objItem.Version
 	objRS("WindowsDirectory") = objItem.WindowsDirectory
    
    objRS.Update

Next

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")

Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
    objRS("SerialNumber") = objSMBIOS.SerialNumber 
    objRS.Update
next


Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colCOMpn = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objCOMpn in colCOMpn
    objRS("Manufacturer") = objCOMpn.Manufacturer
    objRS("Model") = objCOMpn.Model
    objRS("UserName") = objCOMpn.UserName
    objRS("ComputerName") = strComputer
    objRS("Name") = objCOMpn.Name
    objRS.Update
next   
    
     
' *****************************************
' ''' ''' The problem starts here....
' *****************************************
    
    Set objRS2 = CreateObject("ADODB.Recordset")
		objRS2.CursorLocation = 3
		objRS2.Open "SELECT * FROM inventNIC" , objConn, 3, 3
    
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

     n = 1

   For Each objAdapter in colAdapters
    objRS2("Description") = objAdapter.Description
    objRS2("MACAddress") = objAdapter.MACAddress
    objRS2("DNSHostName") = objAdapter.DNSHostName
    
   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
    objRS2("IPAddress") = objAdapter.IPAddress(i)
      Next
   End If

   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
    objRS2("IPSubnet") = objAdapter.IPSubnet(i)
      Next
   End If
 
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
    objRS2("DefaultIPGateway") = objAdapter.DefaultIPGateway(i) 
     Next
   End If
 
   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
    objRS2("DNSServerSearchOrder") = objAdapter.DNSServerSearchOrder(i) 
      Next
   End If
    
    objRS2("DNSDomain") = objAdapter.DNSDomain(i) 

   If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
    objRS2("DNSDomainSuffixSearchOrder") = objAdapter.DNSDomainSuffixSearchOrder(i) 
      Next
   End If
 
    objRS2("DHCPEnabled") = objAdapter.DHCPEnabled 
    objRS2("DHCPServer") = objAdapter.DHCPServer 

						 
	If Not IsNull(objAdapter.DHCPLeaseObtained) Then
		utcLeaseObtained = objAdapter.DHCPLeaseObtained & vbCrLf
		strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
	Else
		strLeaseObtained = ""
			End If
	objRS2("strLeaseObtained") = objAdapter.strLeaseObtained 


	If Not IsNull(objAdapter.DHCPLeaseExpires) Then
		utcLeaseExpires = objAdapter.DHCPLeaseExpires & vbCrLf
		strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
	Else
		strLeaseExpires = ""
	End If
			
	objRS2("strLeaseExpires") = objAdapter.strLeaseExpires 

	objRS2("WINSPrimaryServer") = objAdapter.WINSPrimaryServer 
	objRS2("WINSSecondaryServer") = objAdapter.WINSSecondaryServer 
objRS2.Update 
 
         n = n + 1   

Next

objRS.Close
objRS2.Close
objConn.Close
 
[1] You can use the same objRS for the purpose of objRS2. Just close it out and re-establish it with the new sql.
[tt]
objRS.close
set objRS=nothing 'optional
objRS.Open "SELECT * FROM inventNIC" , objConn, 3, 3
'etc etc
[/tt]
[2] Where is the addNew in the objRS2 part?

For Each objAdapter in colAdapters
[tt] [blue]objRS2.addNew[/blue]
[/tt]objRS2("Description") = objAdapter.Description
[tt] 'etc...[/tt]

[3] For all the array type return, you always end up adding the last entry overwriting the previous. If you have only one column to take the data in, you can use comma separated string.
[tt]
If Not IsNull(objAdapter.IPAddress) Then
s=""
For i = 0 To UBound(objAdapter.IPAddress)
s=s & objAdapter.IPAddress(i)
if s<>UBound(objAdapter.IPAddress) then
s=s & ","
end if
Next
objRS2("IPAddress")=s
End If
[/tt]
And same for other instance.

 
Amendment
Upon re-read the setup, the following line in [1] should be deleted.
>[self [1]]set objRS=nothing 'optional
[tt][red]'[/red]set objRS=nothing 'optional[/tt]
 
Also, this only needs to be done once in your script

Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
That kind of things is dispersing everywhere that I don't even bother to point out, such as regprov. Just a sign of pasting from here and there. The other excuse is probably it is a fragment of larger script...
 
Thanks tsuji and dm4ever for all your valual posts..

The script is a cut and paste script so all tweaks you know of is valuable.

My next problem is:
... I am running the script on my local pc that have 4 nic (1 cable nic, 1 wireless, 2 vmware nic) all the interfaces are inserted in to the table inventNIC creating 4 rows (one for each nic).

The column compID (datatype=int) in inventTB gets a uniq id for each row as it should but the id number isnt populated in to the inventNIC column compID (datatype=numric). So the data in inventTB (that holds the first objRS data) creates one row for each run. That row with data in inventTB gets a uniq id that should be populated in to inventNIC so you could look att a row in inventTB and find the corresponding nics in inventNIC.

The other thing is that i would want to update rather then inserting new content when a pc that already have run the script is running the script the next time.
For instance..
if ComputerName = Computer1 then update ...



The code looks like this now:

Code:
'On Error Resume Next

Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")


    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")

objConn.Open "DSN=inventcon;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM inventTB" , objConn, 3, 3


Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &"\root\default:StdRegProv")

Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

For Each objItem in colItems
    objRS.AddNew
    objRS("Caption") = objItem.Caption
    objRS("Description") = objItem.Description
    objRS("InstallDate") = objItem.InstallDate
    objRS("Organization") = objItem.Organization
    objRS("OSProductSuite") = objItem.OSProductSuite
    objRS("RegisteredUser") = objItem.RegisteredUser
    objRS("ServicePackMajorVersion") = objItem.ServicePackMajorVersion
    objRS("ServicePackMinorVersion") = objItem.ServicePackMinorVersion
    objRS("Version") = objItem.Version
    objRS("WindowsDirectory") = objItem.WindowsDirectory
    
    objRS.Update

Next


Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
    objRS("SerialNumber") = objSMBIOS.SerialNumber 
    objRS.Update
next


Set colCOMpn = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objCOMpn in colCOMpn
    objRS("Manufacturer") = objCOMpn.Manufacturer
    objRS("Model") = objCOMpn.Model
    objRS("UserName") = objCOMpn.UserName
    objRS("ComputerName") = strComputer
    objRS("Name") = objCOMpn.Name
    objRS.Update
next   
   
   
   
Function WMIDateStringToDate(utcDate)
   WMIDateStringToDate = CDate(Mid(utcDate, 5, 2)  & "/" & _
       Mid(utcDate, 7, 2)  & "/" & _
           Left(utcDate, 4)    & " " & _
               Mid (utcDate, 9, 2) & ":" & _
                   Mid(utcDate, 11, 2) & ":" & _
                      Mid(utcDate, 13, 2))
End Function
   
   
    
objRS.close
'set objRS=nothing
Set objRS = CreateObject("ADODB.Recordset")
objRS.Open "SELECT * FROM inventNIC" , objConn, 3, 3

    
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

     n = 1

   For Each objAdapter in colAdapters
   objRS.addNew
    objRS("Description") = objAdapter.Description
    objRS("MACAddress") = objAdapter.MACAddress
    objRS("DNSHostName") = objAdapter.DNSHostName
    
   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
    objRS("IPAddress") = objAdapter.IPAddress(i)
      Next
   End If

   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
    objRS("IPSubnet") = objAdapter.IPSubnet(i)
      Next
   End If
 
   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
    objRS("DefaultIPGateway") = objAdapter.DefaultIPGateway(i) 
     Next
   End If
 
   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
    objRS("DNSServerSearchOrder") = objAdapter.DNSServerSearchOrder(i) 
      Next
   End If
    
    objRS("DNSDomain") = objAdapter.DNSDomain(i) 

   If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
    objRS("DNSDomainSuffixSearchOrder") = objAdapter.DNSDomainSuffixSearchOrder(i) 
      Next
   End If
 
    objRS("DHCPEnabled") = objAdapter.DHCPEnabled 
    objRS("DHCPServer") = objAdapter.DHCPServer 

                         
    If Not IsNull(objAdapter.DHCPLeaseObtained) Then
        utcLeaseObtained = objAdapter.DHCPLeaseObtained & vbCrLf
        strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
    Else
        strLeaseObtained = ""
            End If
    objRS("strLeaseObtained") = strLeaseObtained 


    If Not IsNull(objAdapter.DHCPLeaseExpires) Then
        utcLeaseExpires = objAdapter.DHCPLeaseExpires & vbCrLf
        strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
    Else
        strLeaseExpires = ""
    End If
            
    objRS("strLeaseExpires") = strLeaseExpires 

    objRS("WINSPrimaryServer") = objAdapter.WINSPrimaryServer 
    objRS("WINSSecondaryServer") = objAdapter.WINSSecondaryServer 
objRS.Update 
 
         n = n + 1   

Next

objRS.Close
objConn.Close



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top