Windows XP Annoyances Free Open Book

Windows XP Annoyances

Previous PageNext Page

9.7 Manipulating Internet Explorer from Scripts

Because VBScript owes its existence, in part, to Internet Explorer (IE), it seems only fair that there would be some integration between WSH and IE. The key is the Internet Explorer object and the properties and methods associated with it.

Note that the code in this section is not presented as a subroutine, mostly because all of the subsequent statements that reference the IEObject object (such as IEObject.Document.Write) would fail if the initial Set statement was isolated in it's own routine.

Begin with the following lines in your script, which start the Internet Explorer application, initialize an object to reference, and open a blank IE window:

Set IEObject = CreateObject("InternetExplorer.Application")
If Err.number <> 0 Then
  MsgBox "There was a problem starting Internet Explorer."
  wScript.Quit
End If
IEObject.Left = 75
IEObject.Top = 75
IEObject.Width = 400
IEObject.Height = 300
IEObject.Menubar = 0
IEObject.Toolbar = 0
IEObject.Navigate "About:Blank"
IEObject.Visible=1
Do while IEObject.Busy
  Rem—wait for window to open --
Loop

Note the error checking at the beginning, which quits if there's a problem loading Internet Explorer. The subsequent commands customize the window to our needs; the Left, Top, Width, and Height properties are all in pixels; for the MenuBar and Toolbar properties, 0 means hidden and 1 means visible. Lastly, the Navigate property specifies the URL to load; in this case, we specify About:Blank to show a blank page.

Once the IEObject.Visible=1 command is issued, the window appears, and the real fun begins. (Okay, maybe fun is too strong of a word.) The following lines send HTML code to the active IE window, and form a simple web page:

IEObject.Document.Write "<html>"
IEObject.Document.Write "<h1>Hello World</h1>"
IEObject.Document.Write "<p>"
IEObject.Document.Write "<i>Aren't we sick of that phrase yet?</i>"
IEObject.Document.Write "</html>"

This has nearly limitless possibilities, not the least of which is a more elegant way to display information than the MsgBox command, a much more sophisticated way of gathering information than the InputBox command (using fill-out forms), and a way to display an ongoing log of a script's activities without interrupting script flow. To clear the page at any time, simply issue another IEObject.Navigate "About:Blank" command.

Note that the IE window stays open after the script completes; use the IEObject.Quit command to close the window during script execution.

Previous PageNext Page


     Main Menu
Cover
Copyright
Preface
Chapter 1. Making the Most of Windows XP
Chapter 2. Basic Explorer Coping Skills
Chapter 3. The Registry
Chapter 4. Tinkering Techniques
Chapter 5. Maximizing Performance
Chapter 6. Troubleshooting
Chapter 7. Networking and Internetworking
Chapter 8. User Accounts and Administration
Chapter 9. Scripting and Automation
9.1 Building a Script with VBScript
9.2 Running Applications from Scripts
9.3 Accessing the Registry from Scripts
9.4 Manipulating Files from Scripts
9.5 Creating Windows Shortcuts and Internet Shortcuts in Scripts
9.6 Networking with Scripts
9.7 Manipulating Internet Explorer from Scripts
9.8 Using Command-Line Parameters in Scripts
9.9 Managing Services with Scripts
9.10 Writing CGI Scripts for a Web Server
9.11 Making a Startup Script
9.12 Deciphering Script Errors
9.13 Finding a Better Editor
9.14 Further Study
9.15 Automating Scripts with Scheduled Tasks
9.16 Wacky Script Ideas
Chapter 10. Installing Windows XP
Appendix A. Setting Locator
Appendix B. BIOS Settings
Appendix C. Command Prompt Crash Course
Appendix D. TCP/IP Ports
Appendix E. Error Messages (Blue Screen of Death)
Colophon


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele