AutomationFactory.CreateObject throws当前上下文不支持此操作 [英] AutomationFactory.CreateObject throws This operation is not supported in the current context

查看:74
本文介绍了AutomationFactory.CreateObject throws当前上下文不支持此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我创建了非常简单的使用Silverlight 5的Silverlight应用程序,我试图在浏览器中运行它但是代码在AutomationFactory时不断抛出异常.CreateObject函数被调用,异常说"此操作在当前上下文中不支持
",我按照以下链接中的步骤介绍如何在浏览器内应用程序中提升信任但没有运气:


http:// msdn。 microsoft.com/en-us/library/gg192793(v=VS.95).aspx


对Application.Current.HasElevatedPermissions属性的调用不管是什么都会返回false我试过了。


我试图调用的代码非常简单(见下文),我在本地机器上运行Visual Studio 2010中的代码,在VS IDE中按F5 。

 var cmd = AutomationFactory.CreateObject(" WScript.Shell"); 
cmd.Run(@" C:\ windows \\\
otepad.exe");

我也试图禁用IE保护模式但是仍然没有运气,我也用管理员权限运行VS但它没有用。


任何机构都知道我需要具备提升权限才能运行上述代码吗?


我正在附加异常消息的快照,因为它包含堆栈跟踪信息,它可能会有所帮助。


解决方案



起初,我按照你给出的文章让Trusted Applications在浏览器中运行,但是我遇到了同样的问题,然后我发现在Silverlight 5中我们只需要选中一个复选框如下图所示:

 

Bes ides,下面是我的测试代码:

 

 private void Button_Click(object sender,RoutedEventArgs e){if(App.Current.HasElevatedPermissions){using(dynamic cmd = AutomationFactory.CreateObject(" WScript.Shell") ;)){cmd.Run(@" C:\ WINDOWS \ NOTEPAD.EXE",1,true); } 

然后,结果:



最好的问候,

Qimin Ding


Hello,

I have created very simple Silverlight Application that uses Silverlight 5 and I am trying to run it In-Browser but the code keeps throwing an exception when the AutomationFactory.CreateObject function is called, the exception says "This operation is not supported in the current context", I followed the steps in the below link on how to give elevated trust inside In-Browser application but with no luck:

http://msdn.microsoft.com/en-us/library/gg192793(v=VS.95).aspx

The call to Application.Current.HasElevatedPermissions property keeps returning false no matter what I tried.

The code I am trying to call is very simple (see below) and I am running the code from inside Visual Studio 2010 on my local machine by pressing F5 in the VS IDE.

var cmd = AutomationFactory.CreateObject("WScript.Shell");
cmd.Run(@"C:\windows\notepad.exe");

I also tried to disable the IE protected mode as well but still no luck, I also ran VS with Administrator privilege but it didn't work.

Any body have any idea what do I need to have elevated permissions to run the above code please?

I am attaching a snapshot for the exception message am getting since it contains the stack trace information, it might be helpful.

解决方案

Hi,
At first, I was follow the article you gave to make Trusted Applications to Run Inside the Browser , but I encounter same problem which you have, then I found that In silverlight 5 we just need to select a checkbox like the picture below showing :
 
Besides, below is my test code:
 

private void Button_Click(object sender, RoutedEventArgs e)        {            if (App.Current.HasElevatedPermissions)            {                using (dynamic cmd = AutomationFactory.CreateObject("WScript.Shell"))                {                    cmd.Run(@"C:\WINDOWS\NOTEPAD.EXE", 1, true);                }            }         }

Then, the result:

Best Regards,
Qimin Ding


这篇关于AutomationFactory.CreateObject throws当前上下文不支持此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆