Tune Up Your PC

Tune up your PC with our tools and information today!

  • Home
  • About

27

Mar

UAC - Accessing Internet Explorer

Posted by admin  Published in windows, xp

Accessing Internet Explorer can be useful for obtaining Web content. The usual approach uses a COM object called InternetExplorer.Application like this:


$ie = New-Object -comObject InternetExplorer.Application
$ie.visible = $true
$ie.navigate(‘http://www.powershell.com’)
$ie
$ie.Document


Unfortunately, this approach fails when you use IE with enhanced security (Vista UAC for example). While you can open IE and navigate to the Web page, you will lose access to the document property once the Web site is loaded because the COM object works only for local files. Once you navigate to a Web page, IE launches again with lower privileges, and PowerShell has no way of accessing the new instance.


To work around this issue, you can use yet another COM object called Shell.Application. It returns all Explorer windows, including all open IE windows. All you need do is pick the IE window you need, by specifying a keyword found in its title bar.


The following example launches a Web page and then waits until a browser window opened with the word “PowerShell” in its title bar. Next, the code returns the IE object and accesses the Web page content.


& “$env:programfiles\Internet Explorer\iexplore.exe” ‘http://powershell.com’

$win = New-Object -comObject Shell.Application
$try = 0
$ie2 = $null
do {
 
Start-Sleep -milliseconds 500
 
$ie2 = @($win.windows() | ? { $_.locationName -like ‘*PowerShell*’ })[0]
 
$try ++
 
if ($try -gt 20) {
    Throw
“Web Page cannot be opened.”
  }
}
while ($ie2 -eq $null)

$ie2.document
$ie2.Document.body.innerHTML


http://powershell.com/cs/blogs/tips/archive/2009/04/03/accessing-internet-explorer.aspx 


 http://www.pvle.be/2009/06/web-ui-automationtest-using-powershell/

Related Articles

  • I knew where Nepal was before Raiders of the Lost Ark. Did you? (September 3rd, 2010)
  • Steve Marx Reads The Azure Tea Leaves on Connected Show #36 (September 3rd, 2010)
  • Не место красит разработчика, а… (September 3rd, 2010)
  • Quote of the Day: On the Efficiency of Government (September 3rd, 2010)
  • What happens to a named object when all handles to it are closed? (September 3rd, 2010)

No user responded in this post

Subscribe to this post comment rss or trackback url

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

Categories

  • computers (59)
  • email (3)
  • hardware (17)
  • Operating Systems (1)
  • security (27)
  • software (87)
  • spam (2)
  • technology (93)
  • windows (12402)
  • wireless (3)
  • xp (12397)

Archives

  • September 2010 (75)
  • August 2010 (741)
  • July 2010 (904)
  • June 2010 (594)
  • May 2010 (776)
  • April 2010 (881)
  • March 2010 (728)
  • February 2010 (794)
  • January 2010 (645)
  • December 2009 (710)
  • November 2009 (625)
  • October 2009 (653)
  • September 2009 (622)
  • August 2009 (629)
  • July 2009 (627)
  • June 2009 (652)
  • May 2009 (607)
  • April 2009 (629)
  • March 2009 (465)
  • February 2009 (40)
  • November 2008 (157)
  • October 2008 (140)

Recent Entries

  • I knew where Nepal was before Raiders of the Lost Ark. Did you?
  • What happens to a named object when all handles to it are closed?
  • Quote of the Day: On the Efficiency of Government
  • Не место красит разработчика, а…
  • Steve Marx Reads The Azure Tea Leaves on Connected Show #36
  • This is a really cool panoramic stitching tool!
  • Microsoft Dynamics ERP Licensing Guide
  • Fortnightly MSDN Flash poll
  • Analyzing Database Roundtrips with SQL Server Profiler
  • Windows Identity Foundation Samples–HTTP Watch Is Your Friend

Recent Comments

  • No Comments
  • Random Selection of Posts

    • From about:blank to bing.com
    • ARCast.TV - SharePoint Deployment to Microsoft BPOS Cloud
    • Why use SQL Server 2008 R2 BPA? Case 1: Missing Updates…..
    • Tamper Resistant Controllers and APIs (to Seal or not to Seal?)
    • Exposing Custom WCF Headers through WCF Behaviors - Part 2
    • DVD Shrink for Windows shrinks and copies
    • The OData Deep Dive with Woody is coming to Chicago and Madison
© 2008 Tune Up Your PC is proudly powered by WordPress
Theme designed by Roam2Rome