Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Bad Variable Type when calling via COM

Reply
 
Old 06-19-2008   #1 (permalink)
Colin Bowern


 
 

Bad Variable Type when calling via COM

I'm trying to run a method, SetUserNamePassword, exposed via COM in
PowerShell. Here is the interop interface:

[ComImport, TypeLibType((short) 0x10c0),
Guid("6C55C473-D33C-11D2-8B6F-006097B01206")]
public interface IWMSAdminAnonUser
{
[DispId(7)]
string AnonymousUserName { [return: MarshalAs(UnmanagedType.BStr)]
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(7)] get; }
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(8)]
void SetUserNamePassword([In, MarshalAs(UnmanagedType.LPWStr)] string
newUserName, [In, MarshalAs(UnmanagedType.LPWStr)] string newPassword);
[DispId(9)]
bool IsPasswordSet { [MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(9)] get; }
}

The error I'm getting back:

Exception calling "SetUserNamePassword" with "2" argument(s): "Bad variable
type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE))"

I'm passing in two strings to keep it simple:

$Plugin.SetUserNamePassword("COMPUTER\foo", "bar");

Any thoughts as to what might be the cause?

Thanks,
Colin

My System SpecsSystem Spec
Old 06-20-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Bad Variable Type when calling via COM

Quote:

> I'm passing in two strings to keep it simple:
>
> $Plugin.SetUserNamePassword("COMPUTER\foo", "bar");
>
> Any thoughts as to what might be the cause?
Could it be the "\"? Is there a way for you to try without?

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-20-2008   #3 (permalink)
Colin Bowern


 
 

Re: Bad Variable Type when calling via COM

Hi Marco,

I have tried with and without. The call when written in a C# console app
works, so I'm wondering if there is a marshaling issue that PowerShell isn't
handling properly? The product group shipped a primary interop assembly with
an interface I could map to but I can't figure out how to do the equivalent of

"AnonUser = Plugin.CustomInterface as
Microsoft.WindowsMedia.Interop.IWMSAdminAnonUser"

in PowerShell. I also tried doing a bunch of late binding stuff with no luck.

"Marco Shaw [MVP]" wrote:
Quote:

> Could it be the "\"? Is there a way for you to try without?
My System SpecsSystem Spec
Old 06-20-2008   #4 (permalink)
Marco Shaw [MVP]


 
 

Re: Bad Variable Type when calling via COM

Colin Bowern wrote:
Quote:

> Hi Marco,
>
> I have tried with and without. The call when written in a C# console app
> works, so I'm wondering if there is a marshaling issue that PowerShell isn't
> handling properly? The product group shipped a primary interop assembly with
> an interface I could map to but I can't figure out how to do the equivalent of
>
> "AnonUser = Plugin.CustomInterface as
> Microsoft.WindowsMedia.Interop.IWMSAdminAnonUser"
>
> in PowerShell. I also tried doing a bunch of late binding stuff with no luck.
Outside my comfort zone... There are other more experienced programmers
that check this group regularly that might be able to help.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-20-2008   #5 (permalink)
Karl Prosser[MVP]


 
 

Re: Bad Variable Type when calling via COM

I might be off track, but have you tried the same thing with powershell
V2 with STA threading? Some com objects have horrid problems when called
from a MTA Thread.
Colin Bowern wrote:
Quote:

> Hi Marco,
>
> I have tried with and without. The call when written in a C# console app
> works, so I'm wondering if there is a marshaling issue that PowerShell isn't
> handling properly? The product group shipped a primary interop assembly with
> an interface I could map to but I can't figure out how to do the equivalent of
>
> "AnonUser = Plugin.CustomInterface as
> Microsoft.WindowsMedia.Interop.IWMSAdminAnonUser"
>
> in PowerShell. I also tried doing a bunch of late binding stuff with no luck.
>
> "Marco Shaw [MVP]" wrote:
Quote:

>> Could it be the "\"? Is there a way for you to try without?
>
My System SpecsSystem Spec
Old 06-20-2008   #6 (permalink)
Marco Shaw [MVP]


 
 

Re: Bad Variable Type when calling via COM

Karl Prosser[MVP] wrote:
Quote:

> I might be off track, but have you tried the same thing with powershell
> V2 with STA threading? Some com objects have horrid problems when called
> from a MTA Thread.
I've never actually been able to find a COM component that suddenly
worked when switching between MTA and STA....

Reading up on it a bit recently, only the overall performance may be
affected.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-20-2008   #7 (permalink)
Karl Prosser[MVP]


 
 

Re: Bad Variable Type when calling via COM

How about the clipboard calls?

Marco Shaw [MVP] wrote:
Quote:

> Karl Prosser[MVP] wrote:
Quote:

>> I might be off track, but have you tried the same thing with
>> powershell V2 with STA threading? Some com objects have horrid
>> problems when called from a MTA Thread.
>
> I've never actually been able to find a COM component that suddenly
> worked when switching between MTA and STA....
>
> Reading up on it a bit recently, only the overall performance may be
> affected.
>
> Marco
>
My System SpecsSystem Spec
Old 06-20-2008   #8 (permalink)
Marco Shaw [MVP]


 
 

Re: Bad Variable Type when calling via COM

Karl Prosser[MVP] wrote:
Quote:

> How about the clipboard calls?
>
> Marco Shaw [MVP] wrote:
Quote:

>> Karl Prosser[MVP] wrote:
Quote:

>>> I might be off track, but have you tried the same thing with
>>> powershell V2 with STA threading? Some com objects have horrid
>>> problems when called from a MTA Thread.
>>
>> I've never actually been able to find a COM component that suddenly
>> worked when switching between MTA and STA....
>>
>> Reading up on it a bit recently, only the overall performance may be
>> affected.
>>
>> Marco
>>
OK, that kind of sounds familiar... I don't recall the details though.

I'll search on it. I don't think errors were thrown though if it was
just a wrong aparment state.

Marco
My System SpecsSystem Spec
Old 06-20-2008   #9 (permalink)
Colin Bowern


 
 

Re: Bad Variable Type when calling via COM

Hi Karl,

I haven't tried v2 yet. With the product group saying that they will need a
year or so (give or take a quarter) I'm holding off including PSHv2 on our
production environment servers.

Cheers,
Colin

"Karl Prosser[MVP]" wrote:
Quote:

> I might be off track, but have you tried the same thing with powershell
> V2 with STA threading? Some com objects have horrid problems when called
> from a MTA Thread.
> Colin Bowern wrote:
Quote:

> > Hi Marco,
> >
> > I have tried with and without. The call when written in a C# console app
> > works, so I'm wondering if there is a marshaling issue that PowerShell isn't
> > handling properly? The product group shipped a primary interop assembly with
> > an interface I could map to but I can't figure out how to do the equivalent of
> >
> > "AnonUser = Plugin.CustomInterface as
> > Microsoft.WindowsMedia.Interop.IWMSAdminAnonUser"
> >
> > in PowerShell. I also tried doing a bunch of late binding stuff with no luck.
> >
> > "Marco Shaw [MVP]" wrote:
Quote:

> >> Could it be the "\"? Is there a way for you to try without?
> >
>
My System SpecsSystem Spec
Old 06-20-2008   #10 (permalink)
Karl Prosser[MVP]


 
 

Re: Bad Variable Type when calling via COM

I understand that. I was just thinking to see if its an STA issue or
not, on a test box, to help isolate the problem.
Colin Bowern wrote:
Quote:

> Hi Karl,
>
> I haven't tried v2 yet. With the product group saying that they will need a
> year or so (give or take a quarter) I'm holding off including PSHv2 on our
> production environment servers.
>
> Cheers,
> Colin
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Display actual file type, not description of the type Vista file management
Display the actual type, rather than the description of the type Vista General
Unable to find type [Drawing.Image]: make sure that the assembly containing this type is loaded PowerShell
Calling parameters as a variable PowerShell
How can I ensure that a variable is a built-in powershell variable? PowerShell


Vista Forums 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 Ltd

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