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

发布于 2024-09-03 17:45:29 字数 139 浏览 4 评论 0原文

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

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

I'm planning to build a download manager application and would like to be able to launch the application when a user clicks a button the site. The application would obviously already need to be installed on the client machine.

There are a few reasons why this needs to be written using Silverlight, but they're not really relevant to the question. I only mention it so that people don't suggest that I use another technology.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情深缘浅 2024-09-10 17:45:29

对另外两篇文章进行了一些混搭 [1]和 [2< /a>]。

但当然这仅适用于 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);

    }
}

Doing a bit of a mash up from two other posts [1] and [2].

But of course this will only work for Windows not Mac. There you will have to fallback to the @michael-s-scherotter style solution.

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);

    }
}
眼角的笑意。 2024-09-10 17:45:29

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

  1. 当用户第一次安装 silverlight OOB 应用程序时,从桌面上 OOB 应用程序的快捷方式文件中检索路径和参数值。 (参考:如何在 Silverlight OOB 中使用 Shell32.dll< /a>) 如果您知道路径和参数值,则可以使用 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);
}

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

I found a trick that launches the installed silverlight OOB from the silverlight app in-browser. Both applications should be singed and have the elevated trust.

  1. When a user installs the silverlight OOB App first time, retrive the path and argument values from the shortcut file of the OOB app on desktop. (ref: How I can use Shell32.dll in Silverlight OOB) If you know the the path and argument values, you can launch the OOB app using Com Object.
  2. Send the retrive the path and argument values to the silverlight App in-browser. (ref: http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx)
  3. Store the path and argument values in a cookie.
  4. Now, the silverlight app in-browser is able to launch the silverlight OOB using the path and argument values in the cookie.
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
    shell.Run(launchPath);
}

I hope this trick is useful to you :)

咿呀咿呀哟 2024-09-10 17:45:29

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

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

It is possible if you agree to install the app each time the user clicks on it.

You also should set the app to require elevated trust in its OOB settings.

Just uninstall the app on startup (for example, in main window constructor):

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);
    }
}

(the code for uninstall was taken from this post: http://www.wintellect.com/blogs/sloscialo/programmatically-uninstalling-silverlight-out-of-browser-application)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文