PowerShellでは、MTAで、$ie.document.parentwindowが見えない。
STAでは見えます。なので、PowerShell_ISEで見えます。
ps1ファイルでは、MTAならSTAで起動し直します。
if([Threading.Thread]::CurrentThread.GetApartmentState() -eq "MTA"){
PowerShell -Sta -File $MyInvocation.MyCommand.Path
exit
}
$ie=new-object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("about:blank")
while($ie.busy -or ($ie.readystate -ne 4)){sleep 1}
$ie.document.parentwindow.focus()
あるいは、ScriptControlで逃げます。
$ie=new-object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("about:blank")
while($ie.busy -or ($ie.readystate -ne 4)){sleep 1}
$sc=new-object -com scriptcontrol
$sc.language="vbscript"
$sc.addobject("ie",$ie)
$sc.executestatement("ie.document.parentwindow.focus()")
« PowerShellのConvertTo-HTML出力をHTAウィンドウに表示、印刷、名前を付けて保存する。 | トップページ | out-ie.ps1 PowerShellからHTMLをIEに流し込む。(その2) »