代码之家  ›  专栏  ›  技术社区  ›  marcnicol

是否可以从网页启动Silverlight 4 OOB应用程序?

  •  3
  • marcnicol  · 技术社区  · 14 年前

    为什么需要使用Silverlight来编写这篇文章,有几个原因,但是它们与这个问题并不相关。我提到它只是为了让人们不建议我使用另一种技术。

    5 回复  |  直到 14 年前
        1
  •  1
  •   Community CDub    7 年前

    从另外两个帖子做了一点混搭[ 1 ]以及[ 2 ].

    @michael-s-scherotter 风格解决方案。

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
        {
    
            string run = "\""%ProgramFiles%\\Microsoft Silverlight\\sllauncher.exe"\" /emulate:"Silverface.xap" /origin:\"http://www.silverlight.net/content/samples/apps/facebookclient/ClientBin/Silverface.xap\" /overwrite";
            dynamic cmd = ComAutomationFactory.CreateObject("WScript.Shell");
            cmd.Run(run, 1, true);
    
        }
    }
    
        3
  •  0
  •   Community CDub    7 年前

    我发现了一个从浏览器中的silverlight应用程序启动已安装silverlight OOB的技巧。这两个应用程序都应该签名,并具有更高的信任度。

    1. 当用户第一次安装silverlight OOB应用程序时,从桌面上OOB应用程序的快捷方式文件中检索路径和参数值(裁判: How I can use Shell32.dll in Silverlight OOB )如果知道路径和参数值,可以使用Com对象启动OOB应用程序。
    2. 将检索路径和参数值发送到浏览器中的silverlight应用程序(裁判: http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx )
    3. 将路径和参数值存储在cookie中。
    4. 现在,浏览器中的silverlight应用程序可以使用cookie中的路径和参数值启动silverlight OOB。

    using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
    {
        shell.Run(launchPath);
    }
    

    我希望这个技巧对你有用:)

        4
  •  0
  •   Oleg Gordeev    10 年前

    如果您同意在用户每次单击应用程序时安装该应用程序,这是可能的。

    您还应该将应用程序设置为需要提升对其OOB设置的信任。

    只需在启动时卸载应用程序(例如,在主窗口构造函数中):

    if (Application.Current.HasElevatedPermissions && Application.Current.InstallState == InstallState.Installed)
    {
        string launcherPath = string.Empty;
        using (dynamic shell = AutomationFactory.CreateObject("Shell.Application"))
        {
            string launcher64 = @"C:\Program Files (x86)\Microsoft Silverlight";
            string launcher32 = @"C:\Program Files\Microsoft Silverlight";
    
            dynamic folder64 = shell.NameSpace(launcher64);
            if (folder64 != null)
            {
                launcherPath = launcher64;
            }
            else
            {
                dynamic folder32 = shell.NameSpace(launcher32);
                if (folder32 != null)
                {
                    launcherPath = launcher32;
                }
            }
        }
    
        using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
        {
            var origin = Application.Current.Host.Source.OriginalString;
            var launchCmd = string.Format(@"""{0}\sllauncher.exe"" /uninstall /origin:""{1}""", launcherPath, origin);
            shell.Run(launchCmd);
        }
    }
    

    (卸载代码取自以下帖子: http://www.wintellect.com/blogs/sloscialo/programmatically-uninstalling-silverlight-out-of-browser-application )