Re: Need Help..

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

I think the main problem is that the function IsConnectible returns True if
the computer responds to the ping, but you attempt to update your database
only if it returns False. In the function, note that InStr(fFile.ReadAll,
"TTL=") will be other than zero if the computer responds, it will be zero if
the computer does not respond.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Dennis" <Dennis@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4072E6BE-1B32-4E38-922B-9FC1E2EDF1CB@xxxxxxxxxxxxxxxx
Hi to U all,

I'm a scripting newbe and need help with a script. (thanks alot!!!)
This script is part of a solution that queries a OU container in AD.
Some information must be recored in a Database (If this works we will use
WMI to collect data from computers).
Before it will collect data it checks if de computer is online. This
function is working.
But there are no records added in the database.

This is my script:

===================================================
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.

'
'
' Write Computer Info to Database
'
Call subConnectionOpen
Call subWriteComputerInfo
Call subConnectionClose

WScript.echo "Finished Collection Information for the System."

'------------DataBase Connectie openen --------------------------------


Sub subConnectionOpen
Set objCon = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
sProviderName = "Microsoft.Jet.OLEDB.4.0"
iCursorType = 1
iLockType = 3
sDataSource = "dbCompInfo.mdb"
objCon.Provider = sProviderName
objCon.Properties("Data Source") = sDataSource
objCon.Open
End Sub

'----------- DataBase Connectie sluiten -------------------------------

Sub subConnectionClose
Set objRS = Nothing
Set objCon = Nothing
End Sub

'----------- Computer informatie ophalen en plaatsen in database ------

Sub subWriteComputerInfo

'On Error Resume Next

Set colComputers = GetObject("LDAP://CN=Computers, DC=Contoso, DC=com")
For Each objComputer In colComputers
strComputer = objComputer.CN

If IsConnectible(strComputer, 3, 1000) = False Then

'WScript.echo strComputer & " Niet Verbonden!"
objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblComputer"
objRS.ActiveConnection = objCon
objRS.Open
objRS.AddNew
objRS("strComputer") = strComputer
objRS.Update
intCompID = objRS("ID")
objRS.Close

Else

'WScript.echo strComputer & " Verbonden!"

End if

Next

End Sub


'----------------------------------------------------------------------


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used


Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim oShell, oFSO, sTempFile, fFile


If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750


Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")


sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName


oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True


Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)


Select Case InStr(fFile.ReadAll, "TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select


fFile.Close
oFSO.DeleteFile(sTempFile)


End Function

=============== End script =============================


.



Relevant Pages

  • Re: Need Help..
    ... this part of the script is working. ... The part where we must add disconnected computers to the database i can't ... Dim strComputerName ' The Computer Name to be queried via WMI ... Dim iCursorType ' The Cursor Type for the Recordset ...
    (microsoft.public.windows.server.scripting)
  • Re: Need Help..
    ... strComputer, strName, strModel, etc. works, then I can only guess the ... this part of the script is working. ... The part where we must add disconnected computers to the database i can't ... Dim strComputerName ' The Computer Name to be queried via WMI ...
    (microsoft.public.windows.server.scripting)
  • Re: Moving flat file to a mainframe
    ... launches a script that uses DAO to execute a query that exports the ... 'Sample VBScript to export data from an MDB database to a CSV file ... Dim oTDef 'As DAO.TableDef ... Dim strSQL 'As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Is This Possible ... ? Yes - Upload images to an Access database
    ... It looks like your databases folder is outside the root of your web ... I created a database exactly as you said, the only change I made was to ... and underneath an 'upload' button and a 'view images' button. ... Dim con As New Data.OleDb.OleDbConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is This Possible ... ? Yes - Upload images to an Access database
    ... It looks like your databases folder is outside the root of your web ... I created a database exactly as you said, the only change I made was to ... and underneath an 'upload' button and a 'view images' button. ... Dim con As New Data.OleDb.OleDbConnection ...
    (microsoft.public.dotnet.framework.aspnet)