TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Reply
 
Thread Tools Display Modes
Old 20-06-2008, 09:51 AM   #1
Colin Bowern
Guest
 
Posts: n/a
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
  Reply With Quote
Old 20-06-2008, 03:46 PM   #2
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Bad Variable Type when calling via COM


> 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
  Reply With Quote
Old 20-06-2008, 07:56 PM   #3
Colin Bowern
Guest
 
Posts: n/a
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:
> Could it be the "\"? Is there a way for you to try without?


  Reply With Quote
Old 20-06-2008, 08:51 PM   #4
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Bad Variable Type when calling via COM

Colin Bowern wrote:
> 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
  Reply With Quote
Old 21-06-2008, 01:51 AM   #5
Karl Prosser[MVP]
Guest
 
Posts: n/a
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:
> 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:
>> Could it be the "\"? Is there a way for you to try without?

>

  Reply With Quote
Old 21-06-2008, 01:51 AM   #6
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Bad Variable Type when calling via COM

Karl Prosser[MVP] wrote:
> 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
  Reply With Quote
Old 21-06-2008, 01:52 AM   #7
Karl Prosser[MVP]
Guest
 
Posts: n/a
Re: Bad Variable Type when calling via COM

How about the clipboard calls?

Marco Shaw [MVP] wrote:
> Karl Prosser[MVP] wrote:
>> 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
>

  Reply With Quote
Old 21-06-2008, 01:52 AM   #8
Marco Shaw [MVP]
Guest
 
Posts: n/a
Re: Bad Variable Type when calling via COM

Karl Prosser[MVP] wrote:
> How about the clipboard calls?
>
> Marco Shaw [MVP] wrote:
>> Karl Prosser[MVP] wrote:
>>> 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
  Reply With Quote
Old 21-06-2008, 05:55 AM   #9
Colin Bowern
Guest
 
Posts: n/a
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:

> 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:
> > 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:
> >> Could it be the "\"? Is there a way for you to try without?

> >

>

  Reply With Quote
Old 26-06-2008, 04:17 PM   #10
Karl Prosser[MVP]
Guest
 
Posts: n/a
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:
> 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
>

  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 12:43 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional