我在PowerShell中創建了一個COM對象:在PowerShell中,如何實現COM對象的事件處理程序?
我需要實現的事件處理程序「NewCivicAddressReport」 $ CivicFactory =新對象-ComObject LocationDisp.CivicAddressReportFactory。我嘗試這樣做:
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中我無法得到它的工作。
我會嘗試'$ CivicFactory | Get-Member-Type Event'來獲取你的對象可以訂閱的所有事件。 – 2011-04-26 19:40:43