Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#在不同的安全上下文中启动Outlook_C#_Outlook_Windows 10 - Fatal编程技术网

C#在不同的安全上下文中启动Outlook

C#在不同的安全上下文中启动Outlook,c#,outlook,windows-10,C#,Outlook,Windows 10,我们有一个WPF应用程序需要显示一个新的Outlook项目,允许用户在发送前进行编辑。应用程序以管理员权限启动,因此如果用户的Outlook已打开,则获取Outlook实例时出错。如何解决?请帮帮我,谢谢。除了在相同的安全环境下启动应用程序,你没什么可做的 如果Outlook在不同的安全上下文下运行,则无法自动执行Outlook。但是,您可以使用从运行对象表(ROT)获取指定对象的运行实例的方法来检测试图获取Outlook实例的情况。例如: Outlook.Application Get

我们有一个WPF应用程序需要显示一个新的Outlook项目,允许用户在发送前进行编辑。应用程序以管理员权限启动,因此如果用户的Outlook已打开,则获取Outlook实例时出错。如何解决?请帮帮我,谢谢。

除了在相同的安全环境下启动应用程序,你没什么可做的

如果Outlook在不同的安全上下文下运行,则无法自动执行Outlook。但是,您可以使用从运行对象表(ROT)获取指定对象的运行实例的方法来检测试图获取Outlook实例的情况。例如:

    Outlook.Application GetApplicationObject()
    {

        Outlook.Application application = null;

        // Check whether there is an Outlook process running.
        if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
        {

            // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
            application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

            if(application == null)
               MessageBox.Show("You need to run Outlook under the same security context");
        }
        else
        {

            // If not, create a new instance of Outlook and log on to the default profile.
            application = new Outlook.Application();
            Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
            nameSpace.Logon("", "", Missing.Value, Missing.Value);
            nameSpace = null;
        }

        // Return the Outlook Application object.
        return application;
    }

因此,当
Outlook.exe
进程存在且您无法获取对象时,您所能做的就是要求用户在相同的安全上下文下运行应用程序。

您需要提供您迄今为止尝试过的内容。有人帮你是不可能的