# VBScript: Reading a HTML File



## Het Irv (Sep 30, 2007)

I can't find anywhere online that gives me a good anwser. If anyone knows of a better forums to post this in please tell me.

I am trying to write a Logon Script for my network that will display a HTML file every two hours (for security reasons). What I have so far will only read .txt files.


```
'Declares varibles
Dim objFSO, objFile, strCharacters

'Open the file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\test.txt", 1)
	'To change the file change the path in the line above

'Read the file
Do Until objFile.AtEndOfStream
    strCharacters = strCharacters & objFile.Read(1)
Loop

'Display the file in a message box every 2 hours.
Do
	Wscript.Echo strCharacters
	WScript.sleep(7200*1000)
		'To change the amount of time change the first number in 
		'the line above to the number of seconds needed.
Loop
```
I don't know much about programming, most of this code has been copied from other places. Any help you can give will be much apreciatied.


----------



## Mosaic1 (Aug 17, 2001)

An html file is a text file. When this text file with the html extension is opened in a browser, the browser interprets the html code and renders the page. 

The script is doing what it is supposed to do. (Although I would use Readall and not do it line by line) It is opening the file as text to read the text no matter what extension the file has. That's what OpenTextFile does. 

What are you trying to accomplish? Did you want to send a message to your Users in html form? Then you really don't want to do it this way. If you let me know I might be able to give you some other options.

Also, why not use Task Scheduler?


----------



## Mosaic1 (Aug 17, 2001)

In order to interpret the code, you need to use a browser. You can start an IE object and have it Navigate to your html file and then get what is known as the inner text, aka the body of the document. . The Browser will have already interpreted it. But if there is anything in that html code which would not be printed in the body, then you wouldn't see it. 

But that would run the html code. If you don't mind doing that, it's another option. It really depends on what your goal is and what this file contains.


----------



## Het Irv (Sep 30, 2007)

Do you know what the code is to open a IE object.
I assume that it would replace this line in the code.


```
Set objFSO = CreateObject("Scripting.FileSystemObject")
```
This sounds like what I want to do. Thanks for all of your help so far.


----------



## Mosaic1 (Aug 17, 2001)

No. Not really. Always be careful of running any script if you don't understand it.

Copy the contents of the code box to notepad. Name the file whatever.vbs

This will open the file named test.html located on the C: drive and display it's inner text in an echo on screen. It will not show any graphics, any color or font formatting. If the html file is too long, it will be cut off.

This just runs it once and then ends. I would use Task Scheduler to run it every 2 hours.


```
set ie = createobject("internetexplorer.application")
 ie.navigate "C:\test.html"
 do until ie.readystate = 4 : wscript.sleep 10: loop
 Wscript.echo ie.document.body.innerText
 ie.quit
```
 You're welcome.


----------

