我正在尝试获取当前运行的 Outlook 版本或启动 Outlook 以防它未运行,但我在获取或创建 Windows 7 中的 Outlook 应用程序对象时遇到了一些问题. 我认为这与 Vista 和 7 中限制的用户权限有关。我正在使用 Outlook 2010。
编辑:只有在我已经启动了 Outlook 2010 实例时才会出现这些错误。如果Outlook没有启动,应用程序可以顺利运行(它可以自己启动一个Outlook实例)。
如果有人能告诉我如何正确获取 Outlook 应用程序版本,那将非常有帮助。
我正在运行的代码是一个很长的 try-catch block ,它不断触发异常:
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 应用程序实例时:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.
当我尝试获取 Outlook 应用程序实例时:
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
当我尝试通过 Activator 创建实例时
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.
谢谢!
最佳答案
显然,这些错误是因为我在不同的用户权限级别(其中一个是管理员,另一个是普通用户)运行 Outlook 和应用程序而触发的。
关于c# - 在 Windows 7 中获取/创建 Outlook 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3750605/