ClickOnce - 使用参数重新启动应用程序

时间:2014-12-09 18:06:44

标签: c# wpf clickonce

我有一个WPF应用程序,并使用ClickOnce进行部署。 在这个应用程序中,有一个按钮,用于重新启动带参数的应用程序..

代码:

System.Diagnostics.Process.Start(Application.ResourceAssembly.Location, arg);
if (Application.Current != null)
    Application.Current.Shutdown();

但我发现有时属性没有初始化正确,所以在搜索解决方案后 - 我读到了这个:http://blachniet.com/2012/10/20/how-not-to-restart-a-clickonce-application/

阅读后 - 我改变如下:

System.Windows.Forms.Application.Restart();
    if (Application.Current != null)
        Application.Current.Shutdown();

但是现在 - 我有问题 - 应用程序的重启方法 - 不接受传递参数.. 如何才能通过参数重新启动?

感谢。

1 个答案:

答案 0 :(得分:1)

以下是我如何使用参数重新启动ClickOnce应用程序:

var launchUri = "http://yourwebsite.com/yourapp/YourApp.application"
Process.Start(“rundll32.exe”, String.Format(“dfshim.dll,ShOpenVerbApplication {0}?Arg1={1}&Arg2={2}&Arg3={3}”, launchUri, arg1Value, arg2Value, arg3Value));

你的论点是Arg1,Arg2和Arg3。

启动应用程序时,您必须自己解析URI中的args。 URI可在此处获取:

var launchUri = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
相关问题