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

查看:144
本文介绍了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 char:12 + $ Outlook =新对象-ComObject Outlook.Application + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:ResourceUnavailable:(:) [New-Object],COMException + FullyQualifiedErrorId: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表示调用应用程序和COM服务器在不同的安全上下文中运行.如果命令提示符以提升的特权运行,请确保Outlook也以提升的特权启动,或者确保在执行代码时根本不运行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天全站免登陆