• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Binding a powershell variable to the COM Object of a running application.

M

Mugunth

#1
Hi,
I want to bind a variable $ie to an already opened Internet Explorer
Window.
How can this be done?

For single instance applications like itunes or media player,
$itunes = New-Object -comobject ITunes.Application
binds the shell variable to the running itunes app. (if itunes is
running or creates a new instance.)

How can this be done for other applications like, IE, Winword,
powerpoint etc.,?
New-Object, instead creates a new instance of the application.

Regards,
Mugunth
 

My Computer

K

Keith Hill

#2
"Mugunth" <mugunth.kumar@gmail.com> wrote in message
news:1178100329.331768.26600@q75g2000hsh.googlegroups.com...
> Hi,
> I want to bind a variable $ie to an already opened Internet Explorer
> Window.
> How can this be done?
>
> For single instance applications like itunes or media player,
> $itunes = New-Object -comobject ITunes.Application
> binds the shell variable to the running itunes app. (if itunes is
> running or creates a new instance.)
>
> How can this be done for other applications like, IE, Winword,
> powerpoint etc.,?
> New-Object, instead creates a new instance of the application.


This works:

$word =
[System.Runtime.InteropServices.Marshal]::GetActiveObject('Word.Application')

--
Keith
 

My Computer

G

Gilles LAURENT

#3
"Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> a écrit dans le
message de news:7D33D3B3-97F8-4663-B0DB-D9D9146BD3E8@microsoft.com
| "Mugunth" <mugunth.kumar@gmail.com> wrote in message
| news:1178100329.331768.26600@q75g2000hsh.googlegroups.com...
|| Hi,
|| I want to bind a variable $ie to an already opened Internet Explorer
|| Window.
|| How can this be done?
||
|| For single instance applications like itunes or media player,
|| $itunes = New-Object -comobject ITunes.Application
|| binds the shell variable to the running itunes app. (if itunes is
|| running or creates a new instance.)
||
|| How can this be done for other applications like, IE, Winword,
|| powerpoint etc.,?
|| New-Object, instead creates a new instance of the application.
|
| This works:
|
| $word =
|
[System.Runtime.InteropServices.Marshal]::GetActiveObject('Word.Applicat
ion')

Hi,

And what about "InternetExplorer.Application" ?
There's an issue still opened in the french scripting forum

$IE=[System.Runtime.InteropServices.Marshal]::GetActiveObject("InternetE
xplorer.Application")
Exception calling "GetActiveObject" with "1" argument(s): "Operation
unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))"
At line:1 char:62
+ $IE=[System.Runtime.InteropServices.Marshal]::GetActiveObject( <<<<
"InternetExplorer.Application")

We know that Internet Explorer is not registered in the Running Object
Table (ROT). Is there a workaround ?

--
Gilles LAURENT
http://glsft.free.fr
 

My Computer

M

Mugunth

#4
On May 2, 10:13 pm, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
wrote:
> "Mugunth" <mugunth.ku...@gmail.com> wrote in message
>
> news:1178100329.331768.26600@q75g2000hsh.googlegroups.com...
>
> > Hi,
> > I want to bind a variable $ie to an already opened Internet Explorer
> > Window.
> > How can this be done?

>
> > For single instance applications like itunes or media player,
> > $itunes = New-Object -comobject ITunes.Application
> > binds the shell variable to the running itunes app. (if itunes is
> > running or creates a new instance.)

>
> > How can this be done for other applications like, IE, Winword,
> > powerpoint etc.,?
> > New-Object, instead creates a new instance of the application.

>
> This works:
>
> $word =
> [System.Runtime.InteropServices.Marshal]::GetActiveObject('Word.Application')
>
> --
> Keith


Thanks for the post, But again as Laurent replied, is there a
workaround for IE?
 

My Computer

K

Keith Hill

#5
"Mugunth" <mugunth.kumar@gmail.com> wrote in message
news:1178163614.138080.172410@u30g2000hsc.googlegroups.com...
> Thanks for the post, But again as Laurent replied, is there a
> workaround for IE?


Sorry, I wasn't aware that IE doesn't register itself with the ROT. I don't
know of a way to get hold of a running instance of IE app object. :-(

--
Keith
 

My Computer

D

Don Jones [MVP]

#6
Nope. IE's COM interface doesn't support that capability. The most you could
probably do is use the WScript.Shell object to AppActivate the IE window and
send keystrokes to it.

--
Don Jones
Windows PowerShell MVP
Founder: www.ScriptingAnswers.com
Co-Author: "Windows PowerShell: TFM"

"Gilles LAURENT" <glsft@free.fr> wrote in message
news:%230pY%234QjHHA.588@TK2MSFTNGP06.phx.gbl...
> "Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> a écrit dans le
> message de news:7D33D3B3-97F8-4663-B0DB-D9D9146BD3E8@microsoft.com
> | "Mugunth" <mugunth.kumar@gmail.com> wrote in message
> | news:1178100329.331768.26600@q75g2000hsh.googlegroups.com...
> || Hi,
> || I want to bind a variable $ie to an already opened Internet Explorer
> || Window.
> || How can this be done?
> ||
> || For single instance applications like itunes or media player,
> || $itunes = New-Object -comobject ITunes.Application
> || binds the shell variable to the running itunes app. (if itunes is
> || running or creates a new instance.)
> ||
> || How can this be done for other applications like, IE, Winword,
> || powerpoint etc.,?
> || New-Object, instead creates a new instance of the application.
> |
> | This works:
> |
> | $word =
> |
> [System.Runtime.InteropServices.Marshal]::GetActiveObject('Word.Applicat
> ion')
>
> Hi,
>
> And what about "InternetExplorer.Application" ?
> There's an issue still opened in the french scripting forum
>
> $IE=[System.Runtime.InteropServices.Marshal]::GetActiveObject("InternetE
> xplorer.Application")
> Exception calling "GetActiveObject" with "1" argument(s): "Operation
> unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))"
> At line:1 char:62
> + $IE=[System.Runtime.InteropServices.Marshal]::GetActiveObject( <<<<
> "InternetExplorer.Application")
>
> We know that Internet Explorer is not registered in the Running Object
> Table (ROT). Is there a workaround ?
>
> --
> Gilles LAURENT
> http://glsft.free.fr
>
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)