无法以程序方式卸载浏览器外的SIlverlight应用程序
本文关键字:SIlverlight 应用程序 浏览器 卸载 程序 方式 | 更新日期: 2023-09-27 18:26:41
我正试图删除一个Silverlight Out Of Browser应用程序,该应用程序在下面的帖子中以编程方式将参数传递给sllauncher:http://timheuer.com/blog/archive/2010/03/25/using-sllauncher-for-silent-install-silverlight-application.aspx然而,当给定来源时,它不会卸载该应用程序。
事实证明,当您有一个自动更新的out Of Browser应用程序时,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 的所有特性