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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write error description to database? 1

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Greetings, I've taken a script to collect computer information and modified it for our IT dept needs, but I don't know how to capture errors. I only know how to do on error resume next when looping through ip addresses. What would be neat is if I could capture the error info and move on to the next one. Does anybody have any ideas? Thanks.
Code:
' Get Model, Manufacturer, Computername and Memory 
Set CompSysSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem")
For Each CompSys In CompSysSet
strModel = CompSys.Model
ComputerName = CompSys.Name
strVendor = CompSys.Manufacturer
intRAM = Clng(CompSys.TotalPhysicalMemory/1048576 )
Next
I'm looping through a list of ip addresses. some don't really exist and some of the users don't have their machines turned on. Either way, if I comment out the on error statement, it kills my script. Many thanks!!
 
meldrape,

I may not be completly sure how/where this is running, but I believe this will work.

As you stated you will need to use the "On Error Resume next". Then you need to test the error condition. Insert your "output code". Then clear the error object. See the sample script below.

____________

On Error Resume Next
Set Computer = GetObject("winmgmts:")
If Err <> 0 Then
Wscript.Echo Err.Number & " -- " & Err.Description
Err.Clear
End If
'The next line will generate an error "ExcQuery" vs "ExecQuery"
Set ServiceList = Computer.ExcQuery("SELECT * FROM Win32_Service")
If Err <> 0 Then
Wscript.Echo Err.Number & " -- " & Err.Description
Err.Clear
End If

Run this script to see the test.

I hope this helps...

 
Thanks, Hitech, I'll give that a try and let you know how it worked. Many thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top