gpt4 book ai didi

events - 在PowerShell中,如何为COM对象实现事件处理程序?

转载 作者:行者123 更新时间:2023-12-02 23:48:49 26 4
gpt4 key购买 nike

我在PowerShell中创建了一个COM对象:
$ CivicFactory =新对象-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中,我无法正常运行。

最佳答案

您可能对PSEventing感兴趣,它可以处理.NET,COM和WMI对象事件。

关于events - 在PowerShell中,如何为COM对象实现事件处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5790795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com