Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBS Script End of File error

Posted on 2004-10-21
3
Medium Priority
?
1,769 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:Jaidenkell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Sicos
ID: 12371648
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
 
LVL 4

Accepted Solution

by:
Sicos earned 2000 total points
ID: 12371682

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
 

Author Comment

by:Jaidenkell
ID: 12400610
thanks that worked perfectly!  i need to find a better site that documents this stuff...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question