从Windows外壳上下文菜单承担C#多个文件(参数) [英] Taking multiple files (arguments) from Windows shell context menu on C#

查看:132
本文介绍了从Windows外壳上下文菜单承担C#多个文件(参数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个C#应用程序,它需要的文件作为参数,我添加了它外壳上下文菜单下面列出的代码;

I am writing a C# application and it takes files as argument, I added it to shell context menu with code listed below;

if (((CheckBox)sender).CheckState == CheckState.Checked)
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME + "\\command");

                if (key == null)
                {
                    key = Registry.CurrentUser.CreateSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME + "\\command");
                    key.SetValue("", Application.ExecutablePath + " \"%1\"");
                }
            }
            else if (((CheckBox)sender).CheckState == CheckState.Unchecked)
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME);

                if (key != null)
                {
                    Registry.CurrentUser.DeleteSubKeyTree("Software\\Classes\\*\\shell\\" + KEY_NAME);
                }



这是工作不错,但如果我选择多个文件,应用程序的多个实例运行。
为例,如果我选择5个文件,5应用程序是开放的,我怎么能解决这个问题?

It is working good, but if I select multiple files, multiple instances of application running. for example if I select 5 files 5 application is opening, how can I fix this?

推荐答案

检测是否您的应用程序的实例已经的在启动时运行。

Detect if an instance of your application is already running on startup.

如果是这样,发送命令行参数运行的实例并退出新实例。

If it does, send the command line arguments to the running instance and exit the new instance.

这篇关于从Windows外壳上下文菜单承担C#多个文件(参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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