Powershell 无法从命令提示符创建 Outlook COM 对象 [英] Powershell cannot create Outlook COM object from Command Prompt

查看:27
本文介绍了Powershell 无法从命令提示符创建 Outlook COM 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,用于从命令提示符通过 Microsoft Outlook 发送邮件.如果我从 PowerShell 或 ISE 控制台中运行它,这将正常工作.但是当我尝试从经典的 Windows 命令提示符 (cmd.exe) 执行相同的命令时,即使具有管理员权限,它也无法创建 Outlook COM 对象.这是创建 COM 对象的行:

I have a script used to send mails via Microsoft Outlook from command prompt. This works fine if I run it from inside PowerShell or ISE console. But when I tried to execute same from classic Windows Command prompt (cmd.exe) even with Admin privileges, it was unable to create Outlook COM object. Here is the line to create COM object:

$objOutLook = New-Object -com Outlook.Application

这就是我从 cmd.exe 调用我的脚本的方式(管理权限):

This is how I call my script from cmd.exe (Administrative privileges) :

D:>powershell D:MiscBuildTasks.ps1 -sendmail -MailTo 'farrukh@MyMail.com'

D:>powershell D:MiscBuildTasks.ps1 -sendmail -MailTo 'farrukh@MyMail.com'

这里是错误日志:

New-Object : 使用 CLSID 检索组件的 COM 类工厂{0006F03A-0000-0000-C000-000000000046}由于以下原因失败错误:80080005 服务器执行失败(来自 HRESULT 的异常:0x80080005 (CO_E_SERVER_EXEC_FAILURE)).在 D:MiscBuildTasks.ps1:81 字符:12+ $Outlook = 新对象 -ComObject Outlook.Application+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException+ FullQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). At D:MiscBuildTasks.ps1:81 char:12 + $Outlook = New-Object -ComObject Outlook.Application + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

如何通过 cmd.exe(Windows 命令提示符)使其工作?谢谢

推荐答案

CO_E_SERVER_EXEC_FAILURE 在 Outlook 的情况下意味着调用应用程序和 COM 服务器在不同的安全上下文中运行.如果命令提示符以提升的权限运行,请确保 Outlook 也以提升的权限启动,或者在您的代码执行时它根本不运行 - 这样 Outlook 将由您的代码启动,并以同样提升的特权.

CO_E_SERVER_EXEC_FAILURE in case of Outlook means the calling app and the COM server are running in different security contexts. If the command prompt is running with elevated privileges, either make sure Outlook is started with elevated privileges as well or that it does not run at all when your code is executed - this way Outlook will be started by your code and it will run with the same elevated privileges.

这篇关于Powershell 无法从命令提示符创建 Outlook COM 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆