【发布时间】:2014-11-22 04:27:30
【问题描述】:
以下代码在 PowerShell ISE 中运行,但在常规 PowerShell 控制台中运行时,文档对象为空:
$ie = New-Object -COM InternetExplorer.Application
$ie.Navigate('http://www.example.com')
$ie.Visible = $true
do { Start-Sleep -m 100 } while ( $ie.busy )
$document = $ie.document
$window = $document.parentWindow
"Ready state: " + $ie.ReadyState
"Document: " + $document
"Window: " + $window
PowerShell ISE 中的输出:
Ready state: 4
Document: mshtml.HTMLDocumentClass
Window: System.__ComObject
常规 PowerShell 控制台中的输出:
Ready state: 4
Document: mshtml.HTMLDocumentClass
Window:
在 PowerShell.exe 中运行时,$window 和 $document 的所有其他属性为空。为什么会这样以及如何解决?谢谢!
【问题讨论】:
标签: internet-explorer powershell com scripting