![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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 |
|
|
|
#2 |
|
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 PowerGadgets MVP Blog: |
|
|
|
#3 |
|
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? |
|
|
|
#4 |
|
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 PowerGadgets MVP Blog: |
|
|
|
#5 |
|
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? > |
|
|
|
#6 |
|
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 PowerGadgets MVP Blog: |
|
|
|
#7 |
|
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 > |
|
|
|
#8 |
|
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 |
|
|
|
#9 |
|
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? > > > |
|
|
|
#10 |
|
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 > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |