PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Re: Need Source file to be edited with failed ping
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: Need Source file to be edited with failed ping

Réponse
 
LinkBack Outils de la discussion
Vieux 28/11/2007, 23h22   #1
Tom Lavedas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need Source file to be edited with failed ping

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 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/
  Réponse avec citation
Vieux 29/11/2007, 04h37   #2
Rbhurst
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need Source file to be edited with failed ping

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 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/
>

  Réponse avec citation
Vieux 29/11/2007, 07h11   #3
Al Dunbar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need Source file to be edited with failed ping

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" <Rbhurst@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 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/
>>



  Réponse avec citation
Vieux 29/11/2007, 15h43   #4
Rbhurst
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need Source file to be edited with failed ping

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.

"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" <Rbhurst@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 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/
> >>

>
>
>

  Réponse avec citation
Vieux 30/11/2007, 19h01   #5
Al Dunbar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need Source file to be edited with failed ping


"Rbhurst" <Rbhurst@discussions.microsoft.com> wrote in message
news:23ACB39C-B024-4BDD-A35D-D24BDFC8E0C3@microsoft.com...
> 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.


If you are talking about the issue of trying to append to the file you have
open for reading, here is how I understand it:

When a file is open for reading, it is generally locked, and unable to be
modified or appended to. This is because the reading and writing is, more or
less, sequential and synchronous[*]. It is possible for a file to have
multiple concurrent instances of being accessed, but that would need to be
through some sort of indexed I/O, such as is done in some database systems.
The overhead for doing so is not built into vbscript, and would be quite a
problem to script a solution. You might be able to use one of the COM
objects available for accessing database files with queries, but even ADO
does sequential reads (I think).

An alternative approach would be to maintain the computer list in a
spreadsheet, and access the required info by row/cell reference. While
technically feasible, I think that the complexity of the approach would
increase the scripting effort well beyond the benefits that might be
realized from this approach.
[*] another way to look at this is that when you read from a file
line-by-line, each character read does not come directly from the file
itself, but through some kind of buffering system. And when a file is
modified (i.e. changes are committed back to the storage device), this is
often done internally by writing a completely new copy of the file with
changes applied. So line one of the modified file might not be at the same
location it was when the unmodified file was first opened for reading.

First rule of scripting: keep it relatively simple; it's only scripting.

> 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.


There are a lot of good references for the scripting language itself
("VBScript Programmer's Reference" from WROX), as well as some for specific
application areas (for example, "Windows NT/2000 ADSI Scripting for System
Administration" by Thomas Eck), and even a few general purpose books dealing
with the discipline of programming/app development ("Code Complete" by Steve
McConnell). Most of these will show you something about how certain tasks
could be scripted or programmed, but very few will concentrate on the sorts
of misconceptions the beginner might have about how things work.

Scripting is an arcane activity to say the least. Having an interest or
affinity for it as you do is a definite advantage. Much of the available
information is fact-oriented and targetted narrowly, leaving it to the
practitioner to develop his/her own understanding of how it all fits
together, how or why it works, and what is feasible versus what is not. My
best advice at this point can be summarized as:

- follow this and other related newsgroups
(microsoft.public.scripting.vbscript, microsoft.public.scripting.wsh);
- check out the available web sites, including the MS scripting centre;
- ask questions;
- challenge your own understanding about what you think you know.

The last point is the trickiest, as our own assumptions can be so ingrown
and self-evident that we often do not realize what they are let alone that
we have made them. When stuck on some point, learn to ask yourself why you
think a particular way.

I once had a supervisor who wanted me to develop a simple database to keep
track of something (I forget what it was). When I tried to explain to him
that there was no possible solution to the problem this was intended to
solve he said: "I can't imagine how it would be impossible to do this, as it
seems simple to me". He dropped the idea when I suggested that, in order to
actually do it, at least one of us would have to be able to imagine how it
*could* be done!


/Al

> "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" <Rbhurst@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 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/
>> >>

>>
>>
>>



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h52.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,30029 seconds with 13 queries