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

时间:2010-06-02 14:54:33

标签: silverlight silverlight-4.0 silverlight-oob

我打算构建一个下载管理器应用程序,并希望能够在用户单击该站点的按钮时启动该应用程序。显然,应用程序已经需要安装在客户端计算机上。

有几个原因需要使用Silverlight编写,但它们与问题并不真正相关。我只提到它,以便人们不建议我使用其他技术。

5 个答案:

答案 0 :(得分:2)

根据这篇文章post 1和其他post,我认为这是不可能的。 但我不知道MS是否会在最新版本的SL 4中改变它

答案 1 :(得分:1)

从其他两个帖子[1]和[2]进行混搭。

但当然这只适用于Windows而不适用于Mac。在那里,您将不得不回退到@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);

    }
}

答案 2 :(得分:0)

答案 3 :(得分:0)

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

  1. 当用户第一次安装silverlight OOB App时,请从桌面上的OOB应用程序的快捷方式文件中检索路径和参数值。 (ref:How I can use Shell32.dll in Silverlight OOB)如果您知道路径和参数值,则可以使用Com Object启动OOB应用程序。
  2. 将retrive路径和参数值发送到浏览器中的silverlight App。 (参考:http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx
  3. 将路径和参数值存储在cookie中。
  4. 现在,浏览器中的silverlight应用程序可以使用cookie中的路径和参数值启动silverlight OOB。
  5. using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
    {
        shell.Run(launchPath);
    }
    

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

答案 4 :(得分:0)

如果您同意每次用户点击它时都可以安装该应用程序。

您还应该将应用设置为要求在其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