本文介绍了使用CreateOleObject('Outlook.Application')导致“服务器执行失败”。以管理员身份运行时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个Delphi XE2应用。很简单只需调用CreateOleObject('Outlook.Application')并将结果分配给Variant。



如果程序以管理员身份运行,则会失败,并显示服务器执行失败,但是它可以正常工作,并且如果我以登录用户身份运行(没有提升的权限),我可以获得版本号。



这是为什么?以管理员身份运行会阻止其创建对象?

解决方案

此错误是由于安全性之间不匹配引起的上下文。 Outlook是单例,因此CreateOleObject将连接到运行中的Outlook实例(如果可用)。 COM系统拒绝封送具有不同安全上下文的进程之间的调用。



要么确保在调用CreateOleObject时Outlook未运行,要么确保两个进程都在相同的安全上下文中运行。



兑换-其对象系列大致对应于Outlook对象模型中的 Namespace 对象。)。


It's a Delphi XE2 app. Pretty simple. Just calls CreateOleObject('Outlook.Application') and assigns the result to a Variant.

If the program is run as administrator it fails with "Server execution failed", but it works fine and I can get the version number back if I run as the logged in user (without elevated permissions).

Why is this? What is it about running as administrator that stops it from creating the object?

解决方案

This error is due to a mismatch between the security contexts. Outlook is a singleton, so CreateOleObject will connect to the running instance of Outlook if it is available. COM system refuses to marshal calls between processes with different security contexts.

Either make sure Outlook is not running when calling CreateOleObject or make sure both processes run in the same security context.

You can also switch to Extended MAPI (which is a set of dlls loaded in-proc) used directly or through a wrapper (such as Redemption - its RDO family of objects roughly corresponds to the Namespace object in the Outlook Object Model.).

这篇关于使用CreateOleObject('Outlook.Application')导致“服务器执行失败”。以管理员身份运行时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:09