Re: Need Help..
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 8 Nov 2006 16:05:46 -0600
If the script below works, where you add a record with values for fields
strComputer, strName, strModel, etc. works, then I can only guess the
problem is caused by a table constraint. Could one of the missing fields be
required? What error message do you get?
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Dennis" <Dennis@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BCCAB5EE-F085-4ECD-9F4C-45E33034B39F@xxxxxxxxxxxxxxxx
Thanks for the reply Richard...
The thing is, this part of the script is working (part under this reply).
But if we can't ping a computer then we must add empty records with the
computer name into the database.
The part where we must add disconnected computers to the database i can't
get working.
===================================================
Set colComputers = GetObject("LDAP://CN=Computers, DC=Contoso, DC=com")
For Each objComputer In colComputers
strComputer = objComputer.CN
If IsConnectible(strComputer, 3, 1000) = True Then
set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set CompSysSet = objWMIService.ExecQuery("select * from
Win32_ComputerSystemProduct", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
For Each CompSys In CompSysSet
strIdentifyingNumber = Compsys.IdentifyingNumber
strVendor = CompSys.Vendor
strDescription = CompSys.Description
strModel = CompSys.Model
strName = CompSys.Name
next
objRS.CursorType = iCursorType
objRS.LockType = iLockType
objRS.Source = "tblComputer"
objRS.ActiveConnection = objCon
objRS.Open
objRS.AddNew
objRS("strComputer") = strComputer
objRS("strName") = strName
objRS("strModel") = strModel
objRS("strDescription")= strDescription
objRS("strIdentifyingNumber") = strIdentifyingNumber
objRS("strVendor") = strVendor
objRS.Update
intCompID = objRS("ID")
objRS.Close
=================================================
"Richard Mueller" wrote:
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 =============================
.
- Follow-Ups:
- Re: Need Help..
- From: Dennis
- Re: Need Help..
- References:
- Need Help..
- From: Dennis
- Re: Need Help..
- From: Richard Mueller
- Re: Need Help..
- From: Dennis
- Need Help..
- Prev by Date: Re: newbie scripting
- Next by Date: Logoff script(s)
- Previous by thread: Re: Need Help..
- Next by thread: Re: Need Help..
- Index(es):
Relevant Pages
|