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.Netw ork")
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set oFile = oFSO.OpenTextFile(strFileN ame,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?
Dim oFSO, oFile, WshNetwork
Dim strFileName, startaudit, strListName, xvar
strFileName = "c:\audit information\excluded_hosts
Set WshNetwork = CreateObject("Wscript.Netw
Set oFSO = CreateObject("Scripting.Fi
Set oFile = oFSO.OpenTextFile(strFileN
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks that worked perfectly! i need to find a better site that documents this stuff...
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