There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
VBScript: Reading a HTML File


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Het Irv's Avatar
Member with 56 posts.
 
Join Date: Sep 2007
Experience: Windows: Intermediate Linux:Beginner
05-Nov-2007, 02:30 PM #1
VBScript: Reading a HTML File
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.


Code:
'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.
__________________
Sorry about the Icon, but it is my fav OS thru and thru.
Need Ubuntu Help?
http://duels.com/users/register/het_irv
A great MMORGP and its Free.
Mosaic1's Avatar
Distinguished Member with 7,498 posts.
 
Join Date: Aug 2001
07-Nov-2007, 11:34 AM #2
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?

Last edited by Mosaic1 : 07-Nov-2007 11:40 AM.
Mosaic1's Avatar
Distinguished Member with 7,498 posts.
 
Join Date: Aug 2001
07-Nov-2007, 12:01 PM #3
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's Avatar
Member with 56 posts.
 
Join Date: Sep 2007
Experience: Windows: Intermediate Linux:Beginner
07-Nov-2007, 03:41 PM #4
Do you know what the code is to open a IE object.
I assume that it would replace this line in the code.

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
This sounds like what I want to do. Thanks for all of your help so far.
Mosaic1's Avatar
Distinguished Member with 7,498 posts.
 
Join Date: Aug 2001
07-Nov-2007, 04:08 PM #5
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.

Code:
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.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:57 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.