WSH VBS code base

Discussion in 'OT Technology' started by SixFour, Jun 20, 2007.

  1. SixFour

    SixFour Get on your knees and smile like a doughnut! OT Supporter

    Joined:
    Sep 2, 2004
    Messages:
    2,157
    Likes Received:
    0
    Location:
    /home/sixfour
    I wrote this and have it running as a scheduled task every 3 minutes. It works great for about 8-10 hours then the nic locks up on the server. Should I add a pause in between the functions or maybe change the source file I'm pulling the information from to a different file than the one I'm writing to?



    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = False
    objExcel.DisplayAlerts = FALSE

    intRow = 2

    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set objWorkbook = objExcel.Workbooks.Open("Y:\whosup\uptime.xls")
    Set InputFile = objWorkbook

    '*** begin reading loop
    Do Until objExcel.Cells(intRow,1).Value = ""
    strComputer = objExcel.Cells(intRow, 1).Value
    '*** Ping host to ensure that it is accessible.
    blnPing = PingHost
    If blnPing = False Then
    ReportDown
    End If
    intRow = intRow + 1
    Loop
    objExcel.Save()
    'Set objWorkbook = Nothing
    objExcel.Quit()

    '******************************************************************************
    Function PingHost
    Set objShell = CreateObject("WScript.Shell")
    Set objExec = objShell.Exec("ping -n 1 -w 1000 " & strComputer)
    strPingResults = LCase(objExec.StdOut.ReadAll)
    If InStr(strPingResults, "reply from") Then
    PingHost = True
    Else
    PingHost = False
    End If
    End Function
    '******************************************************************************
    '******************************************************************************
    Function ReportDown
    downTime = objExcel.Cells(intRow, 2).Value
    objExcel.Cells(intRow, 2).Value = downTime + 3
    End Function
    '******************************************************************************
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    You might try destroying all of those objects you are creating to free up resources.

    If it were me, I'd use a "real" database like sql server or mysql to place your data in, instead of Excel. Hell, even Access would be better than using the Excel automation.
     
  3. SixFour

    SixFour Get on your knees and smile like a doughnut! OT Supporter

    Joined:
    Sep 2, 2004
    Messages:
    2,157
    Likes Received:
    0
    Location:
    /home/sixfour
    unfortunately, I can't use a "real" database for this project. do you think destroying the objects afterwards will fix the problem?
     
  4. Javi

    Javi New Member

    Joined:
    Sep 13, 2004
    Messages:
    37,785
    Likes Received:
    0
    Location:
    Houston, TX

    On small scripts, not closing objects is not as bad, but since this is running continuously, you should close them.
     
  5. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    it's possible... you should always destroy them just to be safe. Problem is, you'll never know the real outcome if you do or don't close them since the MS VBA shit is all closed source. It's just safe to always free whatever you create. Should be part of normal coding practices, but it sounds like you're not a fulltime developer.
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I would definately not use Excel - installing it on a server is just wrong. Send it to a .csv file. You can pull data from it just as easily.

    BTW, do not search for "reply from", search for "TTL="
     
  7. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    :werd:

    Or even an XML file would be good too. Something driver independent.
     
  8. Tropic

    Tropic The Gladiator Of OT

    Joined:
    Mar 20, 2004
    Messages:
    8,006
    Likes Received:
    0
    whats the point of this code.

    and did you enhance it?? if so.. can i get a copy? =)
     

Share This Page