programming4us
         
 
 
Windows

Scripting Windows 7 with WSH : Scripting Internet Explorer

- Windows 10 Product Activation Keys Free 2019 (All Versions)
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
5/3/2011 11:32:54 AM
Your scripts can control just about everything associated with Internet Explorer:
  • The position and dimensions of the window

  • Whether the menu bar, toolbar, and status bar are displayed

  • The current URL

  • Sending the browser backward and forward between navigated URLs

Displaying a Web Page

To get started, I show you how to use the InternetExplorer object to display a specified URL. You use the Navigate method to do this, and this method uses the following syntax:

InternetExplorer.Navigate URL [, Flags,] [ TargetFramename] [, PostData] [ ,Headers]


InternetExplorerA reference to the InternetExplorer object with which you’re working.
URLThe address of the web page you want to display.
FlagsOne of (or the sum of two or more of) the following integers that control various aspects of the navigation:
 1Opens the URL in a new window
 2Prevents the URL from being added to the history list
 4Prevents the browser from reading the page from the disk cache
 8Prevents the URL from being added to the disk cache
TargetFrameNameThe name of the frame in which to display the URL.
PostDataSpecifies additional POST information that HTTP requires to resolve the hyperlink. The most common uses for this argument are to send a web server the contents of a form, the coordinates of an image map, or a search parameter for an ASP file. If you leave this argument blank, this method issues a GET call.
HeadersSpecifies header data for the HTTP header.

Here’s an example:

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "http://www.microsoft.com/"

Navigating Pages

Displaying a specified web page isn’t the only thing the InternetExplorer object can do. It also has quite a few methods that enable you to navigate backward and forward through visited web pages, refresh the current page, stop the current download, and more. Here’s a summary of these methods:

GoBackNavigates backward to a previously visited page
GoForwardNavigates forward to a previously visited page
GoHomeNavigates to Internet Explorer’s default Home page
GoSearchNavigates to Internet Explorer’s default Search page
RefreshRefreshes the current page
Refresh2Refreshes the current page using the following syntax: Refresh2(Level)
 LevelA constant that determines how the page is refreshed:
  0Refreshes the page with a cached copy
  1Refreshes the page with a cached copy only if the page has expired
  3Performs a full refresh (doesn’t use a cached copy)
StopCancels the current download or shuts down dynamic page objects, such as background sounds and animations

Using the InternetExplorer Object’s Properties

Here’s a summary of many of the properties associated with the InternetExplorer object:

BusyReturns True if the InternetExplorer object is in the process of downloading text or graphics. This property returns False when a download of the complete document has finished.
FullScreenA Boolean value that toggles Internet Explorer between the normal window and a full-screen window in which the title bar, menu bar, toolbar, and status bar are hidden.
HeightReturns or sets the window height.
LeftReturns or sets the position of the left edge of the window.
LocationNameReturns the title of the current document.
LocationURLReturns the URL of the current document.
MenuBarA Boolean value that toggles the menu bar on and off.
StatusBarA Boolean value that toggles the status bar on and off.
StatusTextReturns or sets the status bar text.
ToolBarA Boolean value that toggles the toolbar on and off.
TopReturns or sets the position of the top edge of the window.
TypeReturns the type of document currently loaded in the browser.
VisibleA Boolean value that toggles the object between hidden and visible.
WidthReturns or sets the window width.

Running Through a Sample Script

To put some of the properties and methods into practice, Listing 1 shows a sample script.

Listing 1. Script That Puts the InternetExplorer Object Through Its Paces
Option Explicit
Dim objIE, objWshShell, strMessage, intResult

' Set up the automation objects
Set objIE = WScript.CreateObject("InternetExplorer.Application")
Set objWshShell = WScript.CreateObject("WScript.Shell")

' Navigate to a page and customize the browser window
objIE.Navigate "http://www.wordspy.com/"
objIE.Toolbar = False
objIE.StatusBar = False
objIE.MenuBar = False

' Twiddle thumbs while the page loads
Do While objIE.Busy
Loop

' Get the page info
strMessage = "Current URL: " & objIE.LocationURL & vbCrLf & _
"Current Title: " & objIE.LocationName & vbCrLf & _
"Document Type: " & objIE.Type & vbCrLf & vbCrLf & _
"Would you like to view this document?"

' Display the info
intResult = objWshShell.Popup(strMessage, , "Scripting IE", vbYesNo + vbQuestion)

' Check the result
If intResult = vbYes Then

' If Yes, make browser visible
objIE.Visible = True
Else

' If no, bail out
objIE.Quit
End If
Set objIE = Nothing
Set objWshShell = Nothing


The script begins by creating instances of the InternetExplorer and WScript Shell objects. The Navigate method displays a page, and then turns off the toolbar, status bar, and menu bar. A Do...Loop checks the Busy property and loops while it’s True. In other words, this loop won’t exit until the page is fully loaded. A string variable is used to store the URL, the title, and type of the page, and this string is then displayed in a Popup box, which also asks whether the user wants to see the page. If the user clicks the Yes button, the browser is made visible. If the user clicks the No button, the Quit method shuts down the browser.

Other -----------------
- Scripting Windows 7 with WSH : Programming the WshNetwork Object
- Scripting Windows 7 with WSH : Programming the WshShell Object (part 2)
- Scripting Windows 7 with WSH : Programming the WshShell Object (part 1)
- Scripting Windows 7 with WSH : Programming the WScript Object
- Scripting Windows 7 with WSH : Programming Objects
- Scripting Windows 7 with WSH : Scripts and Script Execution
- Adding Macs to Your Windows 7 Network : Letting Windows Computers See Your Mac Shares
- Adding Macs to Your Windows 7 Network : Using a Mac to Make a Remote Desktop Connection to Windows 7
- Adding Macs to Your Windows 7 Network : Connecting to a Windows Shared Folder
- Adding Macs to Your Windows 7 Network : Connecting to the Windows Network
- Windows 7 : Controlling and Customizing Your Website (part 5) - Viewing the Server Logs
- Windows 7 : Controlling and Customizing Your Website (part 4) - Disabling Anonymous Access
- Windows 7 : Controlling and Customizing Your Website (part 3) - Working Without a Default Document
- Windows 7 : Controlling and Customizing Your Website (part 2) - Setting the Website’s Default Document
- Windows 7 : Controlling and Customizing Your Website (part 1)
- Windows 7 : Adding Folders and Files to the Default Website (part 3) - Adding a Folder to the Default Website
- Windows 7 : Adding Folders and Files to the Default Website (part 2) - Changing the Default Website Home Page
- Windows 7 : Adding Folders and Files to the Default Website (part 1) - Setting Permissions on the Default Website Folder
- Turning Windows 7 into a Web Server : Understanding the Default Website
- Turning Windows 7 into a Web Server : Accessing Your Website
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS