【发布时间】:2012-05-23 09:51:22
【问题描述】:
我正在使用 javascript 和 activex 通过 IE 中的 EntryID 自动打开公用文件夹,并遇到了一些错误。为了调试,我将它重写为一个 power shell 脚本。
$eid = "HEX EntryID FOR PUBLIC FOLDER";
$o = new-object -com outlook.application;
$ns = $o.GetNamespace("MAPI");
#$ns #if this line is commented, error
$f = $ns.GetFolderFromID($eid)
$f.Display();
如果我完全关闭 Outlook,然后运行脚本,我会收到以下错误
Exception calling "GetFolderFromID" with "2" argument(s): "The messaging interface has returned an unknown error. If the problem persists, restart Outlook."
At G:\scripts\outlook.ps1:5 char:25
+ $f = $ns.GetFolderFromID <<<< ($eid)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
如果我取消注释 $ns 行,一切正常,即使它再次被删除。也就是说,在我完全关闭 Outlook 之前,几乎就像 $ns com 对象在我将其输出到控制台之前并没有真正被初始化。
我想知道:
- 为什么调用
$ns可以解决问题 - 为什么 powershell 认为我传递了 2 个参数
- 有没有办法实现这个解决方法 在javascript中
【问题讨论】:
标签: powershell automation outlook activexobject