VBS Script End of File error

First off let me warn you that i'm not a programmer.  i understand some basics in a few languages (mostly php and visual basic) but i'm a system administrator so if the code looks junky, that is why.  Basically, i'm building a script that will run when a user logs into the network and will check to see if the computer name he is using is in a text file.  if it is in the text file, it will skip running a system audit on the box (so if someone logs into a terminal server or another regular server, they arn't making it run an audit 14 times.  Here is the code:



Dim oFSO, oFile, WshNetwork
Dim strFileName, startaudit, strListName, xvar

strFileName = "c:\audit information\excluded_hosts.txt"

Set WshNetwork = CreateObject("Wscript.Network")

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFile = oFSO.OpenTextFile(strFileName,1)


startaudit = 1


Do While not oFile.AtEndOfStream
      strListName = oFile.ReadLine
      If strListName = WshNetwork.ComputerName then
            startaudit = 0
      end if
      
      oFile.SkipLine
Loop


if startaudit = 1 then
      WScript.Echo("The Computer Name was Not in the Host List")
else
      WScript.Echo("Found Computer name!")
end if


<<<END OF CODE>>>>
I'm getting a "input past end of file" with a 800a003e error but i cant figure out why the code wont work.  any ideas?
JaidenkellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SicosCommented:
Hi,

Remove the oFile.SkipLine

When you use oFile.ReadLine the Line pointer is automaticly moved to the next row...
The way your code is build you read the first line and skips the seconden line, read the third line and skip the fourth line.. etc... etc...

Correct code:

Do While not oFile.AtEndOfStream
     strListName = oFile.ReadLine
     If strListName = WshNetwork.ComputerName then
          startaudit = 0
     end if
     
     oFile.SkipLine <-- remove this line
Loop

Greetings,
Sicos
0
SicosCommented:

Hi,

I forgot something..

Do While not oFile.AtEndOfStream
     strListName = oFile.ReadLine
     If strListName = WshNetwork.ComputerName then
          startaudit = 0
          exit do 'We can exit the loop because we found the computer name, there is no need to read the rest.
     end if
     
     ' oFile.SkipLine <-- remove this line
Loop

Greetings,
Sicos
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JaidenkellAuthor Commented:
thanks that worked perfectly!  i need to find a better site that documents this stuff...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.