Home All Groups Group Topic Archive Search About

Need Source file to be edited with failed ping



Author
28 Nov 2007 9:25 PM
Rbhurst
I am currenly using the following script to change the local admin pword on
all my pcs.  I want the servers.txt file to let me know which pcs were not
pingable.  My script is in ADSI.  Could someone please help figure out how to
do this?


On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt", ForReading)

Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)

    Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then



            set objComputer = GetObject("WinNT://" & strcomputer & "")
        objComputer.Filter = Array("User")
            Set objUser = GetObject("WinNT://" & strComputer &
"/administrator")
                Wscript.Echo objUser.Name
            objUser.SetPassword("password")


        Else
            Wscript.Echo strComputer & " could not be reached."
        End If
    Loop
Loop

objTextFile.Close

Author
28 Nov 2007 10:22 PM
Tom Lavedas
On Nov 28, 4:25 pm, Rbhurst <Rbhu***@discussions.microsoft.com> wrote:
Show quote
> I am currenly using the following script to change the local admin pword on
> all my pcs.  I want the servers.txt file to let me know which pcs were not
> pingable.  My script is in ADSI.  Could someone please help figure out how to
> do this?
>
> On Error Resume Next
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt", ForReading)
>
> Do Until objTextFile.AtEndOfStream
>     strComputer = objTextFile.Readline
>     Set objShell = CreateObject("WScript.Shell")
'------------------ changes ------------------
      strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer _
                 & " | find ""TTL="" "
      nRes = objShell.Run(strCommand, 0, true)

         If nRes = 0 Then
'------------------ changes ------------------
>             set objComputer = GetObject("WinNT://" & strcomputer & "")
>             objComputer.Filter = Array("User")
>             Set objUser = GetObject("WinNT://" & strComputer _
                          & "/administrator")
>                 Wscript.Echo objUser.Name
>             objUser.SetPassword("password")
>
>         Else
>             Wscript.Echo strComputer & " could not be reached."
>         End If
'------------------ change ------------------
' deleted     Loop
'------------------ change ------------------
> Loop
>
> objTextFile.Close

See the embedded changes above.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Author
29 Nov 2007 3:37 AM
Rbhurst
I am sorry, but i am new to this, and first, i don't understand what the
changes were that you made, and second, when i ran it, it didn't append my
file called servers.txt.  The appending i want to accomplish is when a
machine is pinged and it doesn't respond, i would like for the servers.txt
file to reflect that the machine that was being pinged didn't respond.  I
have about 1500 machines to reach, so i don't want to have to guess which
ones have been affected by the script and which ones haven't.

Show quote
"Tom Lavedas" wrote:

> On Nov 28, 4:25 pm, Rbhurst <Rbhu***@discussions.microsoft.com> wrote:
> > I am currenly using the following script to change the local admin pword on
> > all my pcs.  I want the servers.txt file to let me know which pcs were not
> > pingable.  My script is in ADSI.  Could someone please help figure out how to
> > do this?
> >
> > On Error Resume Next
> >
> > Const ForReading = 1
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt", ForReading)
> >
> > Do Until objTextFile.AtEndOfStream
> >     strComputer = objTextFile.Readline
> >     Set objShell = CreateObject("WScript.Shell")
> '------------------ changes ------------------
>       strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer _
>                  & " | find ""TTL="" "
>       nRes = objShell.Run(strCommand, 0, true)
>
>          If nRes = 0 Then
> '------------------ changes ------------------
> >             set objComputer = GetObject("WinNT://" & strcomputer & "")
> >             objComputer.Filter = Array("User")
> >             Set objUser = GetObject("WinNT://" & strComputer _
>                           & "/administrator")
> >                 Wscript.Echo objUser.Name
> >             objUser.SetPassword("password")
> >
> >         Else
> >             Wscript.Echo strComputer & " could not be reached."
> >         End If
> '------------------ change ------------------
>  ' deleted     Loop
> '------------------ change ------------------
> > Loop
> >
> > objTextFile.Close
>
> See the embedded changes above.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>
Author
29 Nov 2007 6:11 AM
Al Dunbar
His code was only intended to determine the pingability of each computer and
act accordingly. Perhaps he did not deduce that wanting "the servers.txt
file to tell you: something meant that something was to be appended to it.

Anyway, there are a couple of reasons why it would not be a good idea to try
to append information other than what the script expects to find in this
input file:

- you would need to code it so that the status information was not assumed
by the script to be the name of the next computer to work with;
- having a file open for both reading and writing, and doing both of those
things seems to me to easily result in confusion.

I would suggest that your script open a separate file for appending, and
write the name of each non-pingable file to it. The output of one run could
then be the input of the next until the number of unpingable computers found
was zero. If I were doing this, I might have the file manipulation done by a
batch file in order to keep the vbscipt simple.

So, Tom gave you code that you had trouble understanding, and I have tried
to give you understanding without giving you the code. Which styel do you
prefer?


/Al

Show quote
"Rbhurst" <Rbhu***@discussions.microsoft.com> wrote in message
news:3E13C7AA-79C8-4CCD-838C-45733BFBFB2E@microsoft.com...
>I am sorry, but i am new to this, and first, i don't understand what the
> changes were that you made, and second, when i ran it, it didn't append my
> file called servers.txt.  The appending i want to accomplish is when a
> machine is pinged and it doesn't respond, i would like for the servers.txt
> file to reflect that the machine that was being pinged didn't respond.  I
> have about 1500 machines to reach, so i don't want to have to guess which
> ones have been affected by the script and which ones haven't.
>
> "Tom Lavedas" wrote:
>
>> On Nov 28, 4:25 pm, Rbhurst <Rbhu***@discussions.microsoft.com> wrote:
>> > I am currenly using the following script to change the local admin
>> > pword on
>> > all my pcs.  I want the servers.txt file to let me know which pcs were
>> > not
>> > pingable.  My script is in ADSI.  Could someone please help figure out
>> > how to
>> > do this?
>> >
>> > On Error Resume Next
>> >
>> > Const ForReading = 1
>> >
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt",
>> > ForReading)
>> >
>> > Do Until objTextFile.AtEndOfStream
>> >     strComputer = objTextFile.Readline
>> >     Set objShell = CreateObject("WScript.Shell")
>> '------------------ changes ------------------
>>       strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer _
>>                  & " | find ""TTL="" "
>>       nRes = objShell.Run(strCommand, 0, true)
>>
>>          If nRes = 0 Then
>> '------------------ changes ------------------
>> >             set objComputer = GetObject("WinNT://" & strcomputer & "")
>> >             objComputer.Filter = Array("User")
>> >             Set objUser = GetObject("WinNT://" & strComputer _
>>                           & "/administrator")
>> >                 Wscript.Echo objUser.Name
>> >             objUser.SetPassword("password")
>> >
>> >         Else
>> >             Wscript.Echo strComputer & " could not be reached."
>> >         End If
>> '------------------ change ------------------
>>  ' deleted     Loop
>> '------------------ change ------------------
>> > Loop
>> >
>> > objTextFile.Close
>>
>> See the embedded changes above.
>>
>> Tom Lavedas
>> ===========
>> http://members.cox.net/tglbatch/wsh/
>>
Author
29 Nov 2007 2:43 PM
Rbhurst
Al,

Thanks so much, that is information that I needed.  I was kind of coming to
the conclusion that my servers.txt file was only a static file, not
appendable. 

I like both approaches put together.  I like the answer, but i also want to
know why the answer is the way it is, not just the answer by itself.  Do you
know of any really good books for a beginner to get some knowledge of this
stuff?  I am really just getting started in scripting, and am liking it. 

Show quote
"Al Dunbar" wrote:

> His code was only intended to determine the pingability of each computer and
> act accordingly. Perhaps he did not deduce that wanting "the servers.txt
> file to tell you: something meant that something was to be appended to it.
>
> Anyway, there are a couple of reasons why it would not be a good idea to try
> to append information other than what the script expects to find in this
> input file:
>
> - you would need to code it so that the status information was not assumed
> by the script to be the name of the next computer to work with;
> - having a file open for both reading and writing, and doing both of those
> things seems to me to easily result in confusion.
>
> I would suggest that your script open a separate file for appending, and
> write the name of each non-pingable file to it. The output of one run could
> then be the input of the next until the number of unpingable computers found
> was zero. If I were doing this, I might have the file manipulation done by a
> batch file in order to keep the vbscipt simple.
>
> So, Tom gave you code that you had trouble understanding, and I have tried
> to give you understanding without giving you the code. Which styel do you
> prefer?
>
>
> /Al
>
> "Rbhurst" <Rbhu***@discussions.microsoft.com> wrote in message
> news:3E13C7AA-79C8-4CCD-838C-45733BFBFB2E@microsoft.com...
> >I am sorry, but i am new to this, and first, i don't understand what the
> > changes were that you made, and second, when i ran it, it didn't append my
> > file called servers.txt.  The appending i want to accomplish is when a
> > machine is pinged and it doesn't respond, i would like for the servers.txt
> > file to reflect that the machine that was being pinged didn't respond.  I
> > have about 1500 machines to reach, so i don't want to have to guess which
> > ones have been affected by the script and which ones haven't.
> >
> > "Tom Lavedas" wrote:
> >
> >> On Nov 28, 4:25 pm, Rbhurst <Rbhu***@discussions.microsoft.com> wrote:
> >> > I am currenly using the following script to change the local admin
> >> > pword on
> >> > all my pcs.  I want the servers.txt file to let me know which pcs were
> >> > not
> >> > pingable.  My script is in ADSI.  Could someone please help figure out
> >> > how to
> >> > do this?
> >> >
> >> > On Error Resume Next
> >> >
> >> > Const ForReading = 1
> >> >
> >> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> > Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt",
> >> > ForReading)
> >> >
> >> > Do Until objTextFile.AtEndOfStream
> >> >     strComputer = objTextFile.Readline
> >> >     Set objShell = CreateObject("WScript.Shell")
> >> '------------------ changes ------------------
> >>       strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer _
> >>                  & " | find ""TTL="" "
> >>       nRes = objShell.Run(strCommand, 0, true)
> >>
> >>          If nRes = 0 Then
> >> '------------------ changes ------------------
> >> >             set objComputer = GetObject("WinNT://" & strcomputer & "")
> >> >             objComputer.Filter = Array("User")
> >> >             Set objUser = GetObject("WinNT://" & strComputer _
> >>                           & "/administrator")
> >> >                 Wscript.Echo objUser.Name
> >> >             objUser.SetPassword("password")
> >> >
> >> >         Else
> >> >             Wscript.Echo strComputer & " could not be reached."
> >> >         End If
> >> '------------------ change ------------------
> >>  ' deleted     Loop
> >> '------------------ change ------------------
> >> > Loop
> >> >
> >> > objTextFile.Close
> >>
> >> See the embedded changes above.
> >>
> >> Tom Lavedas
> >> ===========
> >> http://members.cox.net/tglbatch/wsh/
> >>
>
>
>

AddThis Social Bookmark Button