Link to home
Start Free TrialLog in
Avatar of Jaidenkell
Jaidenkell

asked on

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?
Avatar of Sicos
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
ASKER CERTIFIED SOLUTION
Avatar of Sicos
Sicos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jaidenkell

ASKER

thanks that worked perfectly!  i need to find a better site that documents this stuff...