如何从一个ClickOnce应用程序获得命令行? [英] How to get command line from a ClickOnce application?

查看:360
本文介绍了如何从一个ClickOnce应用程序获得命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发布我去项目 - >属性 - >选项 - >文件关联,并添加扩展名.hsp。设置图标和程序id(MyCompany.Document.1进行检测)。当我发布并安装,我.hsp文件有我设置的图标,因此该文件的关联应适当设置,但是当我双击了这些文件,运行应用程序之一,我希望我双击是文件的名称在命令行中。我试着读传递给我的函数的参数,试图 Environment.CommandLine ,并试图 Environment.GetCommandLineArgs(),但我发现的唯一的事情就是应用程序的路径。顺便说一句,我做这一切检查在创建我的主要形式前主的功能,只是为了测试。该的args 参数为空,另两个仅包含我的应用程序的路径。

这是我的函数的开头:

 静态无效的主要(字串[] args)
    {
        尝试
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(假);
            Application.ThreadException + =新ThreadExceptionEventHandler(Application_ThreadException);
            的MessageBox.show(的CommandLine  - >中+ Environment.CommandLine);
            的foreach(在args字符串str)的MessageBox.show(的args  - >中+ STR);
            的foreach(在Environment.GetCommandLineArgs字符串str())的MessageBox.show(GetCommandLineArgs  - >中+ STR);
 

解决方案

当你发布使用ClickOnce的应用程序,然后通过双击关联的文件,路径启动它该文件实际上被存储在这里:

AppDomain.CurrentDomain.SetupInformation.Activati​​onArguments.Activati​​onData [0]

有关查阅MSDN文档在这里:

<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.hosting.activationarguments.aspx">http://msdn.microsoft.com/en-us/library/system.runtime.hosting.activationarguments.aspx

另外关于添加文件关联的教程,以已发布项目:

<一个href="http://blogs.msdn.com/b/mwade/archive/2008/01/30/how-to-add-file-associations-to-a-clickonce-application.aspx">http://blogs.msdn.com/b/mwade/archive/2008/01/30/how-to-add-file-associations-to-a-clickonce-application.aspx

Before publishing I went to Project -> Properties -> Options -> File Associations and added the extension ".hsp". Set an icon and a ProgID ("MyCompany.Document.1" for testing). After I published and installed, my .hsp files had the icon I set, so the file association should be properly set, but when I double clicked one of these files the application run and I expected the name of the file I double clicked to be in the command line. I tried reading the parameter passed to my Main function, tried Environment.CommandLine, and tried Environment.GetCommandLineArgs(), but the only thing I found was the application path. By the way I'm doing all this check before creating my main form in the Main function, just to test. The args parameter is empty and the other two only contain my app path.

This is the beginning of my Main function:

    static void Main(string[] args)
    {
        try
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            MessageBox.Show("CommandLine -> " + Environment.CommandLine);
            foreach (string str in args) MessageBox.Show("args -> " + str);
            foreach (string str in Environment.GetCommandLineArgs()) MessageBox.Show("GetCommandLineArgs -> " + str);

解决方案

When you publish an app with ClickOnce and then launch it by double-clicking an associated file, the path to that file actually gets stored here:

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]

See MSDN's documentation for it here:

http://msdn.microsoft.com/en-us/library/system.runtime.hosting.activationarguments.aspx

Plus a tutorial on adding file associations to "Published" projects:

http://blogs.msdn.com/b/mwade/archive/2008/01/30/how-to-add-file-associations-to-a-clickonce-application.aspx

这篇关于如何从一个ClickOnce应用程序获得命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆