Script Tips

You Command, IE Obeys

How to get Internet Explorer to do your bidding.

Here's a quick and dirty way to make Internet Explorer do your bidding and display fancier messages than VBScript's good ol' MsgBox() allows.

Keep in mind that IE is just another COM application and, as such, is highly scriptable. You'll create an instance of it in your script, and gain complete control over how IE behaves and looks:

Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")

Nice and easy. Now you can tell IE to navigate to a page, such as the special blank page:

oIE.Navigate "about:blank"

Although of course you could use any URL you like. You can also control the appearance and position of the IE window:

oIE.ToolBar = 0 'Turn off the toolbar
oIE.Status = 0 'Turn off the status bar
oIE.MenuBar = 0 'Turn off the menu
oIE.Width = 400
oIE.Height = 200
oIE.Left = 10
oIE.Top = 10

With all of that work, you might want to give IE a second to compose itself:

Do While oIE.Busy
  WScript.Sleep 200
Loop

Finally, make IE show its face:

oIE.Visible = 1

Of course, you'll also want to stick some HTML into IE. Perhaps you want to display a status message in red:

oIE.Document.Body.InnerHTML = "
  "color=red>WARNING!"

When you're done having IE show off, you can close it on command:

oIE.Quit

This is a great way to show customized, HTML-formatted dialog boxes and status messages as part of your scripts. Check out the "Misc VBScript and WSH" section of the ScriptVault on ScriptingAnswers.com for more IE scripting fun.

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is Curriculum Director for IT Pro Content for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus
Most   Popular