是否可以从网页启动Silverlight 4 OOB应用程序?
问题描述:
我打算构建一个下载管理器应用程序,并希望能够在用户单击该网站按钮时启动该应用程序。该应用程序显然已经需要安装在客户端机器上。是否可以从网页启动Silverlight 4 OOB应用程序?
有几个原因需要使用Silverlight编写,但它们与问题无关。我只提到它,以便人们不会建议我使用其他技术。
答
的最后一个版本来自另外两个职位[1]和[2]这样做有点混搭的了。
但当然这只适用于Windows而不适用于Mac。在那里你必须回退到@michael-s-scherotter风格的解决方案。
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);
}
}
答
我发现,在浏览器的Silverlight应用程序启动安装了Silverlight OOB一招。这两个应用程序应该被烧录并且具有较高的信任度。
- 当用户第一次安装Silverlight OOB App时,从桌面上的OOB应用程序的快捷方式文件中检索路径和参数值。 (ref:How I can use Shell32.dll in Silverlight OOB)如果您知道路径和参数值,则可以使用Com对象启动OOB应用程序。
- 将路径和参数值发送给浏览器中的silverlight应用程序。 (ref:http://msdn.microsoft.com/en-us/library/dd833063(v=vs.95).aspx)
- 将路径和参数值存储在cookie中。
- 现在,浏览器中的silverlight应用程序能够使用cookie中的路径和参数值启动silverlight OOB。
using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
{
shell.Run(launchPath);
}
我希望这招对你有用:)
答
,如果你同意给每个用户点击它时安装的应用程序这是可能的。
您还应该设置应用程序以在其OOB设置中要求提升信任度。
只需卸载在启动应用程序(例如,在主窗口的构造函数):
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);
}
}
(用于卸载的代码是从这个帖子采取:http://www.wintellect.com/blogs/sloscialo/programmatically-uninstalling-silverlight-out-of-browser-application)
谢谢回答。解决方案不是我正在寻找的。它只显示你已经安装了这个应用程序,请从你的快捷方式启动它。要卸载/重新安装,请右键单击此处并选择“删除此应用程序...”。我想要做的是OOB应用程序在用户点击网页上的按钮或在浏览器中运行的应用程序时启动。 – marcnicol 2010-06-02 15:21:55
这是因为你已经安装了应用程序。 您可以创建一个SL应用程序,在浏览器中只显示安装按钮,但在运行OOB时显示完整的用户界面。 – 2010-06-02 15:43:35
我想启动已安装的应用程序。 – marcnicol 2010-06-02 15:54:25