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 .NET General
Object Binding Query .NET General
Is binding a datacontext to a CLR object correct ? Avalon
How can I ensure that a variable is a built-in powershell variable? PowerShell
Binding to same DP on another instance of same object won't work. Avalon