简体   繁体   English

从C#上的Windows shell上下文菜单中获取多个文件(参数)

[英]Taking multiple files (arguments) from Windows shell context menu on C#

I am writing a C# application and it takes files as argument, I added it to shell context menu with code listed below; 我正在编写一个C#应用程序,它将文件作为参数,我将它添加到shell上下文菜单中,代码如下所示;

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);
                }

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? 例如,如果我选择5个文件5应用程序正在打开,我该如何解决这个问题?

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. 如果是, 请将命令行参数发送到正在运行的实例并退出新实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM