惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
D
DataBreaches.Net
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Y
Y Combinator Blog
博客园 - 【当耐特】
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
量子位
C
Check Point Blog
F
Fortinet All Blogs
罗磊的独立博客
Last Week in AI
Last Week in AI
GbyAI
GbyAI
L
LangChain Blog
博客园 - 司徒正美

博客园 - davin

Beginning Asp.Net Security 读书笔记-----XSS phonegap3.0+HTMLl5 开发 ipad app 总结 移动支付-修复FireFox在android移动设备下面的Session 丢失的问题 Window.history.forward(1) 阻止页面后退详解 Pro WPF and Silverlight MVVM:第5章 Event and Command 读书笔记 Pro WPF and Silverlight MVVM 第4章ViewModel 读书笔记 Silverlight4:Devexpress Report Useful rules for compatible with FF,safari and ie8 Entity Framework 4.0 FK Properties && FK Associations Entity Framework 4.0 recipes 读书笔记2 ExecuteStoreQuery() Entity Framework 4.0 Recipes 读书笔记1 EDM中的 Complex Type sqlserver2008 + team foundation server 2008 sp1 silverlight animation 读书笔记(4)三角函数 silverlight animation 读书笔记(3)坐标与向量 silverlight animation 读书笔记<2>模糊, 裁剪,拖拽 foundation silverligh3 animation 读书笔记<1>transform Entity Framework object && Json 序列化的问题 silverlight3:(ItemControl 的)UI Virtualization SharpZipLib 数据压缩
在silverlight中打开调用外部程序的几种方式
davin · 2010-08-15 · via 博客园 - davin

在silverlight中调用外部程序的几种方法总结如下:

1.silverlight不支持oob模式的时候,silverlight调外部应用程序只能通过activex来实现。

   大致方法如下,之前写的一个:

       var idropItems;
        var clsid;
        var plugin;
        var currentDivIndex;
        jQuery(document).ready(function() {
            idropItems = window.parent.GetIDropItems();
            if (idropItems.length > 0) {

                BuildDivContainer();

                //activex的clsid,

                clsid = "clsid:21E0CB95-1198-4945-A3D2-4BF804295F78";
                $("#Pagination").pagination(idropItems.length, {
                    num_edge_entries: 2,
                    num_display_entries: 8,
                    items_per_page: 8,
                    next_text: "",
                    prev_text: "",
                    callback: pageselectCallback
                });
            }
        });
        function pageselectCallback(page_id, jq) {
            BuildIDropItems(page_id);
        }

   function BuildIDropItems(pageIndex) {

            $("#c_" + currentDivIndex).hide();
            if ($("#c_" + pageIndex).attr("loaded") == "0") {
                var itemIndex = pageIndex * 8;
                var html = "";
                for (var i = itemIndex; i < itemIndex + 8; i++) {
                    if (i < idropItems.length) {
                        if (idropItems[i].ObjectType == '2') {
                            var objectName = GetSubstring(idropItems[i].ObjectName.substring(0, idropItems[i].ObjectName.lastIndexOf('.')), 13);
                            var ext = idropItems[i].ObjectName.substring(idropItems[i].ObjectName.lastIndexOf('.') + 1).toLowerCase();
                                                         html += "<div class='ItemBox'>";
                                html += "<object classid='" + clsid + "' width='101' height='101' >";
                                html += "<param name='background' value=''>";
                                html += "<param name='proxyrect' value='0, 0, 101, 101'>";
                                html += "<param name='griprect' value='0, 0, 101, 101'>";
                                html += "<param name='package'  value='GetIDropItem.aspx?guid=" + idropItems[i].ObjectId + "&type=xml'>";
                                html += "<param name='validate' value='1'>";
                                html += "<img src='GetIDropItemguid=" + idropItems[i].ObjectId + ".img' title= />";
                                html += "</object>";
                                html += "<span class='ItemName'>" + objectName + "</span>";
                                html += "</div>";                                      

                        }
                    }
                }
                $("#c_" + pageIndex).html(html).attr("loaded", "1");
            }
            $("#c_" + pageIndex).show();
            currentDivIndex = pageIndex;
        }

2.在silverlight4里面,可以在oob模式下可以直接调com组件,如下面代码段:就是通过AutomationFactory调用dt930的com组件
      if (Application.Current.InstallState != InstallState.Installed)
          Application.Current.Install();

      //oob模式,需要提升权限
      if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
       {

          ///AutomationFactory call com componnnet          
            dynamic dt = AutomationFactory.CreateObject("DT390COM.DT390");

      }
需引用下面的命名空间

using System.Dynamic;

using System.Windows.Interop;
using System.Runtime.InteropServices.Automation;

3.上面2种方法都要求调用的外部程序是com组件,如果不是com组件,又该如何去启动外部程序呢.通过使用WScript.Shell 组件可以打开任何的应用程序

  eg  using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
         {
                shell.Run(@"C:\windows\notepad.exe"); //you can open anything
               shell.SendKeys(txtTextToSend.Text);
               
          }

  除此之外还可以在js中调用

      <javascript language="javascipt">{

       var shell = new ActiveXObject("WScript.shell");

       shell.Run(@"C:\windows\notepad.exe");

    }