![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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. 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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. 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 >> I'll search on it. I don't think errors were thrown though if it was just a wrong aparment state. Marco |
My System Specs![]() |
| | #9 (permalink) |
| | 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 Specs![]() |
| | #10 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||