Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Windows Scripting Learning Guide Chapter 4 and already stuck :(

Back to Forum: Tech Off
  • User profile image
    Greater Monster

    The following script is actually direct from the CD that came with the book (Microsoft Windows Scripting Self-Paced Learning Guide)

    Running it without arguments gives the correct message.

    When I give one or more arguments, it gives an error:
    pingmultiplecomputers.vbs(10,1) (null): 0x80041010

    This is the command:
    cscript pingmultiplecomputers.vbs computer1;computer2
    where computer1 is the local machine and computer2 a machine on the network. I have no administrator rights on computer2

    This is the script:
    If WScript.Arguments.Count = 0 Then
    WScript.Echo("You must enter a computer To ping")
    strMachines = WScript.Arguments.Item(0)
    aMachines = split(strMachines, ",")
    For Each machine In aMachines
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
    ExecQuery("select * from Win32_PingStatus where address = '"_
    & machine & "'")
    For Each objStatus In objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
        WScript.Echo("machine " & machine & " is not reachable")
        wscript.Echo("reply from " & machine)
        End If
    End If

    Line 10 in the error message is this:
    For Each objStatus In objPing

    I run it on a W2K pro station.

    What obvious point am I overlooking?

  • User profile image

    If you don't have admin on comp2, then objPing is probably null for that comp, which means you can't execute your For Each statement. Just a guess, though.

  • User profile image

    Surely the command should be

    cscript pingmultiplecomputers.vbs computer1,computer2
    (use comma instead of semicolon), as it splits the string on the , deliminator:
    aMachines = split(strMachines, ",")

  • User profile image
    Greater Monster

    Thank you both, as you both had part of the solution.
    It turned out I had no administrative rights on comp1 as well. Also I should have used the comma. I was alternating between two scripts which were the expect for the comma and semicolon.
    I did use cscript but forgot to type it.

    Again thanks to both of you, I am back on track (and got a reminder from that typo and syntax error are a programmers' nightmare).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.