我有 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 中——除了虚拟方法。
有人对此有解释吗?