Solved

VBS Script End of File error

Posted on 2004-10-21
1,755 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
Question by:Jaidenkell
    3 Comments
     
    LVL 4

    Expert Comment

    by:Sicos
    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:

    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
    thanks that worked perfectly!  i need to find a better site that documents this stuff...
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Title # Comments Views Activity
    Tool to format notepad++ 1 54
    fizzArray  challenge 1 22
    has77  challenge 9 47
    Fix45 challenge 15 50
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now