Question

I'm trying to remove a Silverlight Out Of Browser app programatically passing the arguments to sllauncher in following this post: http://timheuer.com/blog/archive/2010/03/25/using-sllauncher-for-silent-install-silverlight-application.aspx However it won't uninstall the app when given the origin.

Was it helpful?

Solution

It turns out that when you have an automatically updating Out-Of-Browser application, Silverlight stamps each application Uri with a time stamp that can be found in the application's folder in the C:\Users\Trevor\AppData\Local\Microsoft\Silverlight\OutOfBrowser(AppFolderName) metadata file. So to facilitate the removal of our app in preparation for our new one, I implemented the following:

UninstallExisting(GetInstalledAppUri()); // This is how it's called
//This is the two method's implementation

// TODO: Change to your app name.    
const string appName = "YourAppNameHere";

static string silverlightOutOfBrowserFolder = 
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 
    + @"\Microsoft\Silverlight\OutOfBrowser";

private static string GetInstalledAppUri()
    {
        string xapFolderPath = Path.Combine(silverlightOutOfBrowserFolder, GetXapFolder());
        string[] lines = File.ReadAllLines(Path.Combine(xapFolderPath, "metadata"), Encoding.Unicode);
        string finalAppUriLine = lines.First(i => i.Contains("FinalAppUri="));
        return "\"" + finalAppUriLine.Replace("FinalAppUri=", "") + "\"";
    }

    private static string GetXapFolder()
    {
        string AppXapFolder = "";
        foreach (var dir in Directory.GetDirectories(silverlightOutOfBrowserFolder))
        {
            if (dir.Contains(appName))
            {
                AppXapFolder = dir;
            }
        }
        return AppXapFolder ;
    }

private static string silverlightExe
    {
        get
        {
            return Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), 
            @"Microsoft Silverlight\sllauncher.exe");
        }
    }

private static void UninstallExisting(string xapUriToRemove)
    {
        string installArgs = "/uninstall" + " /origin:" + xapUriToRemove;
        ProcessStartInfo pstart = new ProcessStartInfo(silverlightExe, installArgs);
        Process p = new Process();
        pstart.UseShellExecute = false;
        p.StartInfo = pstart;
        p.Start();
        p.WaitForExit();
    }

I hope this serves to save someone else the hours of time it took me to figure out about the metadata file and all the peculiarities of sllauncher.exe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top