Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Windows Script

  • Filter
  • Time
  • Show
Clear All
new posts

  • Windows Script

    I wrote the following script and am experiencing a problem with it... What this script is supposed to do is go and ping an ip address and if it gets one of two answers then it will shutdown a unix machine via putty and plink. The two conditions its looking for is either a "reply timed out" or "destination host unreachable" if it gets either of them back it should run the plink session... If it does find them it should do nothing and just exit. Right now when i run the script.. I does not appear to be doing the check properly. I have been told there are much easier ways of doing this however... this is what i know so far... Assistance would be great..

    Set objShell=CreateObject("")
    Set objWshScriptExec=objShell.exec("ping")
    Set objWshScriptExec2=objShell.exec("d:\plink -load")
    Set objStdOut=objWshScriptExec.Stdout
    While Not objStdOut.AtEndOfStream
     If InStr(strLine,"Reply Timed Out") then
     elseif InStr(strLine,"Destination Host") then
            End If
    Edit by Dumber: wrapped code tags around the script.
    Last edited by Dumber; 10th January 2009, 12:48.

  • #2
    Re: Windows Script

    What is the problem you have - is the machine shutting down when it shouldn't, or is it not being shut down when it should?
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.


    • #3
      Re: Windows Script

      Its shutting down when it should not.


      • #4
        Re: Windows Script

        Originally posted by Tweak View Post
        Its shutting down when it should not.
        That is correct, with the 3rd line Set objWshScriptExec2=objShell.exec("d:\plink -load") plink will be executed before objStdOut.ReadLine begins.

        Try this sample,
        DIM objShell  ' global scope
        Set objShell = CreateObject("WScript.Shell")
        strComputer = ""
        strCommand1 = """d:\plink.exe"" -load"
        If PingResult(strComputer, "TTL=") = False Then
           ' Computer was not connectable
           On Error Resume Next
           errLevel = ,,True)
        End If
        If IsEmpty(errLevel) OR (errLevel <> 0) _
           Then objShell.popup ("plink has not been applied or not executed succesfully"), 2
        Function PingResult(ByVal strHost, ByVal sFind)
          ' function returns "False" (0) or "True" (-1)
          With objShell  ' that has a global scope
             Do While nPings =< 3
                Select Case .Run("%comspec% /c" _
                   & " ping.exe -n 1 -w 750 " & strHost _
                   & " | find/i """ & sFind & """ >nul 2>&1", 0, True)
                      Case 0
                      PingResult = True
                      exit Function
        Case Else PingResult = False
                End Select
                nPings = nPings + 1
        rem  If (not PingResult = True) _
        rem     Then PingResult = False
          End With
        End Function
        Last edited by Rems; 12th January 2009, 09:24.

        This posting is provided "AS IS" with no warranties, and confers no rights.


        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts