com - OCX/COM : Some methods do not show up in PowerShell

标签 com powershell ocx

我有 ActiveX 控件 SetACL.ocx。它已在我的系统上注册,我可以从 C# (Visual Studio 2010) 毫无问题地使用它。 Visual Studio 的对象浏览器显示所有方法。

但是,在 PowerShell 中,大约有三分之一的方法没有显示。如果我尝试调用缺少的方法之一,我会得到 MethodNotFound:

PS C:\> $setacl = New-Object -ComObject setacl.setaclctrl.1
PS C:\> $setacl | Get-Member

   TypeName: System.__ComObject#{85869435-0ee3-440b-bf69-6c52c6638073}

Name                   MemberType Definition
----                   ---------- ----------
AddACE                 Method     int AddACE (string, bool, string, int, bool, int, int)
AddDomain              Method     int AddDomain (string, string, int, bool, bool)
AddTrustee             Method     int AddTrustee (string, string, bool, bool, int, bool, bool)
GetLastAPIError        Method     int GetLastAPIError ()
GetLastAPIErrorMessage Method     string ()
GetLastListOutput      Method     string GetLastListOutput ()
GetResourceString      Method     string GetResourceString (int)
Reset                  Method     void Reset ()
Run                    Method     int Run ()
SetAction              Method     int SetAction (int)
SetListOptions         Method     int SetListOptions (int, int, bool, int)
SetLogFile             Method     int SetLogFile (string)
SetOwner               Method     int SetOwner (string, bool)
SetPrimaryGroup        Method     int SetPrimaryGroup (string, bool)


PS C:\> $setacl.SetObject("test", 1)
Method invocation failed because [System.__ComObject#{85869435-0ee3-440b-bf69-6c52c6638073}] doesn't contain a method named 'SetObject'.
At line:1 char:18
+ $setacl.SetObject <<<< ("test", 1)
    + CategoryInfo          : InvalidOperation: (SetObject:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

关于为什么 PowerShell 不显示所有可用方法但 Visual Studio 的对象浏览器显示的任何线索?

我尝试了 32 位和 64 位版本的 PowerShell。

更新 1:

这是 ODL 文件中缺少的方法之一的签名(是的,我有 OCX 的完整源代码,我是它的作者):
[id(2), helpstring ("Set the object on which all actions are to be performed")]
LONG SetObject(BSTR sObjectPath, LONG nObjectType);

更新 2:

这里是 source code of the OCX ,可在 sourceforge 上直接浏览。

更新 3:

OCX 可以是 downloaded from sourceforge .它包含在文件 SetACL 2.2.0.zip 中。

更新 4 - 可能的解决方案:

将具有 DISPIDs 1-7 的方法更改为更高的 DISPIDS 并引入 7 个具有 DISPIDS 1-7 的新虚拟方法似乎可以解决问题。现在一切都显示在 PoSh 中——除了虚拟方法。

有人对此有解释吗?

最佳答案

查看项目中的 IDL 文件 here ,您的 _DSetACL 接口(interface)中 DISPID 低于 8 的每个成员似乎都被忽略了。也许尝试以更高的索引启动 DISPID,比如 100?我确实记得一些“神奇”的 dispid 值,但我认为它们是极高的值,而不是低值,可能是错误的......

关于com - OCX/COM : Some methods do not show up in PowerShell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5339343/

相关文章:

delphi - 将 COM 对象接口(interface)从 C 转换为 Delphi

.net - 如何在 .net 项目中将 Reg-Free COM 用于 vb6 dll 引用?

powershell - 显示磁盘大小和FreeSpace(以GB为单位)

java - 如何在java中使用ActiveX(ocx)

delphi - 需要 PDF 查看器控制 - 尝试了很多

wpf - Windows 7 x64 上的闪存 ocx "Class not registered"

c# - 如何处理来自控制台应用程序的 COM 事件?

c# - VSTO Excel Com 添加功能区未加载

powershell - powershell 中是否有相当于 "... || die"的值?

powershell - 具有一个可选参数,需要另一个参数