3

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.

marcnicol
  • 180
  • 1
  • 8

4 Answers4

1

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

    }
}
Community
  • 1
  • 1
JProgrammer
  • 2,750
  • 2
  • 25
  • 36
0

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

Community
  • 1
  • 1
user689072
  • 134
  • 8
0

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)

Oleg Gordeev
  • 554
  • 4
  • 6
0

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

Michael S. Scherotter
  • 10,715
  • 3
  • 34
  • 57
  • Thanks for answering. The solution is not quite what I'm looking for. It only shows You have already installed this application, please launch it from your shortcut. To uninstall/reinstall please right click here and choose "Remove this application...". What I would like to do is for the OOB application to start when the user clicks on a button on the web page or in the in application running in browser.. – marcnicol Jun 02 '10 at 15:21
  • That is because you've already installed the app. You can create a SL app that when in-browser just shows an install button but when it is running OOB, it shows the full UI. – Michael S. Scherotter Jun 02 '10 at 15:43
  • I want to launch an application that has already been installed. – marcnicol Jun 02 '10 at 15:54