Is it possible to launch a Silverlight 4 OOB application from a web page?

女生的网名这么多〃 提交于 2019-12-13 14:08:17

问题


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.


回答1:


I think that is not possible according to this post post 1 and to other post. But I don't know if MS will change that in the last version of SL 4




回答2:


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

    }
}



回答3:


Yes. Here is an example: http://www.silverlight.net/content/samples/apps/facebookclient/sfcquickinstall.aspx




回答4:


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




回答5:


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)



来源:https://stackoverflow.com/questions/2958866/is-it-possible-to-launch-a-silverlight-4-oob-application-from-a-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!