2

我有 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:

这是OCX 的源代码,可在 sourceforge 上直接浏览。

更新 3:

OCX 可以从 sourceforge 下载。它包含在文件 SetACL 2.2.0.zip 中。

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

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

有人对此有解释吗?

4

6 回答 6

1

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

于 2011-03-17T20:11:44.090 回答
0

黑暗中的另一个刺...

Get-Member -Force -View All

还要确保您获得正确版本的对象。

于 2011-03-17T18:13:27.013 回答
0

尝试 Get-Member 的 -force 参数?

总猜测顺便说一句...

于 2011-03-17T13:34:58.963 回答
0

试试 Get-Member -Static?再猜。

于 2011-03-17T14:09:39.470 回答
0

这种事情通常发生在没有类型库的情况下。当这种情况发生时,你通常会尝试这样的事情:

$bindingFlags = [System.Reflection.BindingFlags]::InvokeMethod
[System.__ComObject].InvokeMember('SetObject', $bindingFlags , $null, $setacl, 
                                  @("test", 1))
于 2011-03-21T15:23:29.137 回答
0

这看起来像 PowerShell 特定的限制。此处的博客中提到了两种解决方法。

于 2011-03-27T20:59:23.870 回答