Windows Vista Forums

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

  1. #1


    Mugunth Guest

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

    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 System SpecsSystem Spec

  2. #2


    Keith Hill Guest

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

    "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 System SpecsSystem Spec

  3. #3


    Gilles LAURENT Guest

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

    "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 System SpecsSystem Spec

  4. #4


    Mugunth Guest

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

    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 System SpecsSystem Spec

  5. #5


    Keith Hill Guest

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

    "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 System SpecsSystem Spec

  6. #6


    Don Jones [MVP] Guest

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

    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 System SpecsSystem Spec

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

Similar Threads
Thread Forum
Binding TextBox.Text to property in nested (multi levels) object withbindingsource, Error if grandchild object is NULL
Hi all, I am binding a TextBox to an object which has child object which has a grandchild object, and I want to bind to the property of the...
.NET General
Binding to a User Object with Alternate Credentials
Is there a way to bind to a user object with alternate credentials? Here is the line I am using. ' arrADAccounts(intAccountIndex,2) is a 2D '...
VB Script
Object Binding Query
Using Object Binding how can I get changes in the class to update the UI? In a win form VB2005 app I've got a simple class and created the binding...
.NET General
WCF + net.tcp binding + certificates = Communication object is in theFaulted state
Hi All. We are recently in my company working on a large system. It is suppose to have 3 layers (presentation - ASP.NET, middle - WCF server, and...
.NET General
Is binding a datacontext to a CLR object correct ?
There is something that confuses me about databinding. I'd like to know if binding a datacontextproperty to a CLR object is a correct practice. Why...
Avalon
How can I ensure that a variable is a built-in powershell variable?
I have a question regarding variables. Is there a way to ensure that retrieved variable such as *Preference variables are indeed a built-in...
PowerShell
Binding to same DP on another instance of same object won't work.
Hi, I'm trying to bind the value of a custom control DP to the same DP on another instance of the same custom control but receive a message...
Avalon