Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

COM IDispatch and Powershell invocation

Closed Thread
 
Thread Tools Display Modes
Old 09-11-2006   #1 (permalink)
=?Utf-8?B?S2Jnbw==?=
Guest


 

COM IDispatch and Powershell invocation

Can Powershell handle COM invocation with Object implementing Idispatch
interfaces. I would think so, however why can I run a piece of script via the
VBS engine while Powershell failes. Please help!

*********Powershell*********

$b = New-Object -ComObject Station.Application
$b | gm
$b.connect("")



TypeName: System.__ComObject

Name MemberType Definition
---- ---------- ----------
CreateObjRef Method System.Runtime.Remoting.ObjRef
CreateOb...
Equals Method System.Boolean Equals(Object obj)
GetHashCode Method System.Int32 GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method System.Type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
ToString Method System.String ToString()

Method invocation failed because [System.__ComObject] doesn't contain a method
named 'connect'.
At line:1 char:11
+ $b.connect( <<<< "")


*********VBS*********

However, this seems to work.

dim myStation
set myStation = createobject("Station.Application")
myStation.connect("")


Any idea's about the difference? It's my understanding the PowerShell can
handle Idispatch interface for late-bind of COM object. So why doesn't this
work?
Old 09-12-2006   #2 (permalink)
Yuksel Akinci [MSFT]
Guest


 

Re: COM IDispatch and Powershell invocation

Does late-binding works?

[system.__comobject]::invokemember("connect","[system.reflection.bindingflags]::invokemethod,$null,$b,$null)


--
Yuksel Akinci [MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scr.../hubs/msh.mspx
"Kbgo" <Kbgo@discussions.microsoft.com> wrote in message
news:879D3FA3-30BE-4330-B814-B70F84E02DE2@microsoft.com...
> Can Powershell handle COM invocation with Object implementing Idispatch
> interfaces. I would think so, however why can I run a piece of script via
> the
> VBS engine while Powershell failes. Please help!
>
> *********Powershell*********
>
> $b = New-Object -ComObject Station.Application
> $b | gm
> $b.connect("")
>
>
>
> TypeName: System.__ComObject
>
> Name MemberType Definition
> ---- ---------- ----------
> CreateObjRef Method System.Runtime.Remoting.ObjRef
> CreateOb...
> Equals Method System.Boolean Equals(Object obj)
> GetHashCode Method System.Int32 GetHashCode()
> GetLifetimeService Method System.Object GetLifetimeService()
> GetType Method System.Type GetType()
> InitializeLifetimeService Method System.Object
> InitializeLifetimeService()
> ToString Method System.String ToString()
>
> Method invocation failed because [System.__ComObject] doesn't contain a
> method
> named 'connect'.
> At line:1 char:11
> + $b.connect( <<<< "")
>
>
> *********VBS*********
>
> However, this seems to work.
>
> dim myStation
> set myStation = createobject("Station.Application")
> myStation.connect("")
>
>
> Any idea's about the difference? It's my understanding the PowerShell can
> handle Idispatch interface for late-bind of COM object. So why doesn't
> this
> work?



Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method invocation failed B Williams PowerShell 0 03-31-2008 05:46 PM
Remote invocation of ps commands? Duncan Smith PowerShell 5 10-05-2007 12:12 PM
Function names and invocation Hans Dingemans PowerShell 3 09-26-2007 01:12 AM
Late Binding with IDispatch based com objects Vincent.Parrett@gmail.com PowerShell 1 05-09-2007 08:54 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50