【问题标题】:Unable to Uninstall SIlverlight Out Of Browser Application Programatically无法以编程方式从浏览器应用程序中卸载 SIlverlight
【发布时间】:2013-08-09 00:11:03
【问题描述】:

我正在尝试删除一个 Silverlight Out Of Browser 应用程序,以编程方式将参数传递给 sllauncher,遵循此帖子:http://timheuer.com/blog/archive/2010/03/25/using-sllauncher-for-silent-install-silverlight-application.aspx 但是,在给定来源时它不会卸载该应用程序。

【问题讨论】:

    标签: c# silverlight installation uninstallation out-of-browser


    【解决方案1】:

    事实证明,当您有一个自动更新的浏览器外应用程序时,Silverlight 会在每个应用程序 Uri 上加上一个时间戳,该时间戳可以在 C:\Users\Trevor\AppData\Local\ 的应用程序文件夹中找到Microsoft\Silverlight\OutOfBrowser(AppFolderName) 元数据文件。因此,为了便于删除我们的应用以准备我们的新应用,我实施了以下操作:

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

    我希望这可以帮助其他人节省我花费数小时来弄清楚元数据文件和 sllauncher.exe 的所有特性

    【讨论】:

      猜你喜欢
      • 2011-02-13
      • 1970-01-01
      • 2011-05-30
      • 2012-03-17
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      相关资源
      最近更新 更多