【发布时间】:2011-08-13 01:04:22
【问题描述】:
我在 PowerShell 中创建了一个 COM 对象: $CivicFactory = new-object -comObject LocationDisp.CivicAddressReportFactory
我需要为“NewCivicAddressReport”实现事件处理程序。我试过这个:
Register-ObjectEvent $CivicFactory -EventName "NewCivicAddressReport" -Action ({ echo "haha" })
但它给了我"Register-ObjectEvent : Cannot register for event. An event with name 'NewCivicAddressReport' does not exist."
然后我尝试了$CivicFactory.add_NewCivicAddressRerport( {"haha"} )
它也不起作用:方法调用失败,因为[System.__ComObject#{bf773b93-c64f-4bee-beb2-67c0b8df66e0}] doesn't contain a method named 'add_NewCivicAddressRerport'。
谁能告诉我如何在 PowerShell 中实现这个事件处理程序?提前致谢。 在 VBScript 中它就像
一样简单Function CivicFactory_NewCivicAddressReport(report)
Blablabla...
End Function
但在 PowerShell 中我无法正常工作。
【问题讨论】:
标签: events object com powershell handler