在 Windows 7 中获取/创建 Outlook 应用程序

发布于 2024-09-24 03:13:35 字数 1338 浏览 5 评论 0原文

我正在尝试获取当前正在运行的 Outlook 版本,或者在 Outlook 未运行的情况下启动 Outlook,但在 Windows 7 中获取或创建 Outlook 应用程序对象时遇到一些问题。我认为它与 Vista 和 7 中限制的用户权限有关。我正在使用 Outlook 2010。

编辑:仅当我已经启动了 Outlook 2010 实例时,才会出现这些错误。如果 Outlook 未启动,应用程序可以顺利运行(它可以自行启动 Outlook 实例)。

如果有人能告诉我如何正确获取 Outlook 应用程序版本,那将非常有帮助。

我正在运行的代码是一个很长的 try-catch 块,它不断触发异常:


try
{
  // create an application instance of Outlook
  oApp = new Microsoft.Office.Interop.Outlook.Application();
}
catch(System.Exception ex)
{
  try
  {
     // get Outlook in another way
     oApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
  }
  catch (System.Exception ex2)
  {
     // try some other way to get the object
     oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application;
  }
}

应用程序向我抛出以下异常:

当我尝试创建新的 Outlook 应用程序实例时:

由于以下错误,检索 CLSID 为 {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005。

当我尝试获取 Outlook 应用程序实例时:

操作不可用(HRESULT 异常:0x800401E3 (MK_E_UNAVAILABLE))

当我尝试通过激活器创建实例时

由于以下错误,检索 CLSID 为 {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005。

谢谢你!

I'm trying to get the current running version of Outlook or start up Outlook in case it is not running, but I am having some issues in getting or creating the Outlook Application object in Windows 7. I think it has something to do with the user priviliges that are restrictive in Vista and 7. I am working with Outlook 2010.

edit: These errors only appear if I already have an Outlook 2010 instance started. If Outlook is not started, the application can run smoothly (it can start an Outlook instance by itself).

If anybody can tell me how to correctly get the Outlook Application version, that would be really helpful.

The code I'm running is a long try-catch block that keeps on triggering exceptions:


try
{
  // create an application instance of Outlook
  oApp = new Microsoft.Office.Interop.Outlook.Application();
}
catch(System.Exception ex)
{
  try
  {
     // get Outlook in another way
     oApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
  }
  catch (System.Exception ex2)
  {
     // try some other way to get the object
     oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application;
  }
}

The application throws me the following exceptions:

When I try to create a new Outlook application instance:

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

When I try to get the Outlook app instance:

Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

When I try to Create an instance through the Activator

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

青衫负雪 2024-10-01 03:13:35

显然,这些错误是因为我在不同的用户权限级别(其中一个作为管理员,另一个作为普通用户)运行 Outlook 和应用程序而触发的。

Apparently these errors were triggered because I was running Outlook and the application on different user permission levels (one of them as administrator and the other one as regular user).

转身以后 2024-10-01 03:13:35
  1. 在开始菜单中选择运行
  2. 类型 dcomcnfg 并单击确定,
  3. 将打开组件服务窗口。
  4. 展开节点组件服务 ->我的电脑-> DCOM 配置。
  5. 右键单击应用程序(Outlook 邮件附件)并选择属性。
  6. 根据需要单击“身份”选项卡。
  7. 单击“交互式用户”,然后单击“确定”
  1. In start menu select Run
  2. Type dcomcnfg and click OK
  3. Component Services window is opened.
  4. Expand the nodes Component Services -> MyComputer -> DCOM Config .
  5. Right click on the application (Outlook Message Attachment) and select properties.
  6. Click on Identity tab whatever necessary.
  7. Click on “The interactive user" then OK
转身泪倾城 2024-10-01 03:13:35

确实,如果您从 Visual Studio 运行独立应用程序或从使用 Office 产品的 Visual Studio 进行调试,则您应该对两者(Visual Studio 和 Office 产品)具有相同的访问级别,这就是此问题的原因之一发生,但我在网上看到很多人在初始化服务中的 Outlook 对象时遇到这个问题。我希望为我解决问题的方法也能帮助其他人。请按照步骤操作。

  1. 转到命令提示符,键入以下内容并按 Enter 键。这将打开组件服务:

    mmc comexp.msc /32

在此处输入图像描述

在此处输入图像描述

  1. 展开节点组件服务 ->我的电脑-> DCOM 配置

  2. 现在找到您所需的应用程序(在本例中为 Outlook 邮件附件)并右键单击该应用程序(如果按照以下步骤操作,则可以解决与所有 Office 应用程序相关的此问题)并选择属性。

  3. 转到“身份”选项卡并选择“交互式用户”,然后按“确定”。这应该可以解决您的问题。

在此处输入图像描述

交互式用户只不过是登录用户。当您尝试通过服务访问办公产品时,访问级别必须相同,这就是您需要指定正确用户的原因。如果您想在不登录服务器的情况下在服务器上运行该服务,您需要确保该服务器有一个用户帐户,该帐户将用于运行该服务以及运行“属性”中指定的 Office 产品(请查看属性对话框)。如果您想了解此对话框中提到的不同类型的用户帐户,请参阅以下 Microsoft 链接。

http://msdn。 microsoft.com/en-us/library/windows/desktop/ms692541%28v=vs.85%29.aspx

It is true that if you are running a standalone application from Visual Studio or debugging from Visual Studio which use office products, you should be having same access level for both (Visual Studio and Office Products) and that is one of the reasons why this issue occurs but I am seeing online that so many people have this issue while initializing outlook object in a service. I hope what resolved the issue for me would help others too. Please follow along the steps.

  1. Go to command prompt, type the following and press enter. This opens Component Services:

    mmc comexp.msc /32

enter image description here

enter image description here

  1. Expand the nodes Component Services -> MyComputer -> DCOM Config

  2. Now find out your desired application (In this case, Outlook Message Attachment) and right click on the application (If you follow these steps, this issue related all office applications can be resolved) and select properties.

  3. Go to Identity tab and select The interactive user and press OK. This should resolve your issue.

enter image description here

The interactive user is nothing but the logged on user. When you are trying to access office products through service, the access level has to be same and that is the reason you need to specify proper user. If you want to run the service on a server without logging onto it, you need to make sure that the server has a user account which will be used for running the service as well as running office products as specified in Properties as This user (Please look at the Properties dialog box). If you want to learn about the different types of user accounts mentioned in this dialog box, please refer to the following Microsoft link.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms692541%28v=vs.85%29.aspx

淡淡的优雅 2024-10-01 03:13:35

您的 Office 安装似乎已损坏。

尝试通过以管理员身份重新运行安装程序来修复安装。

It looks as if your Office installation has become corrupted.

Try to repair the installation by rerunning setup as Administrator.

云雾 2024-10-01 03:13:35

就我而言,是 Visual Studio 以管理员身份运行导致了该问题。当我以普通用户身份运行它时,我终于摆脱了这个错误。

In my case it was Visual Studio ran as Administrator causing the issue. When I ran it as normal user I got rid of this error finally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文