Powershell 2 事件处理
我正在尝试使用 Powershell 2.0 编写 Powerpoint 脚本。
此网站表示有一个“PresentationOpen”事件。但是,Get-Member 不显示此事件。另外,当我尝试执行此操作时:
register-objectevent $application PresentationOpen notification_event
它说:“无法注册事件。名称为“PresentationOpen”的事件不存在。”
为什么无法从 PowerShell 访问此事件?难道是我做错了,还有别的办法吗?
我真正想做的是等到演示文稿完全加载后再将其保存为其他格式。不等待有时会导致 PPT 冻结。
我很感激任何帮助!
I'm trying to script Powerpoint with Powershell 2.0.
This site says there's a "PresentationOpen" event. However, Get-Member does not show this event. Also, when I try to do this:
register-objectevent $application PresentationOpen notification_event
it says: "Cannot register for event. An event with name 'PresentationOpen' does not exist."
Why is this event not accessible from PowerShell? Am I doing it wrong, and there is another way?
What I'm really trying to do is to wait until the presentation is fully loaded before I save it in another format. Not waiting causes PPT to freeze sometimes.
I'm grateful for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PowerShell 在 COM 支持方面相当薄弱(它更像 C#,而不是 VB)。在这种情况下,您必须委托该事件。请参阅此页面上的调度:http://support.microsoft.com/kb/308825 /EN-US/
PowerShell is pretty weak in COM support (it's a lot more like C# than it is like VB). In this case, you'll have to delegate the event. See the dispatches on this page: http://support.microsoft.com/kb/308825/EN-US/
可能还有其他(和更好的)方法来执行此操作,但这应该可以帮助您开始:
您可能希望将第二行 -Action 之后的脚本块替换为执行处理/保存的任何代码。
如果您注册的事件有任何输出,您可以通过 Receive-Job cmdlet 处理它,否则您只需在 Open() 方法调用之后添加一个与此类似的循环即可阻止进一步的脚本执行,直到幻灯片已完成打开:
There may be other (and better) ways to do this, but this should get you started:
You would want to replace the script block after -Action on the second line with whatever code would do the processing/saving.
If there is any output from your event that you have registered, you can deal with it through the Receive-Job cmdlet, otherwise you can just simply add a loop similar to this right after the Open() method call to block further script execution until the slide deck has finished opening: