微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在编写一个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);
                }

它运行良好,但如果我选择多个文件,则运行多个应用程序实例.
例如,如果我选择5个文件5应用程序正在打开,我该如何解决这个问题?

解决方法

检测 instance of your application is already是否在启动时运行.

如果是,请执行send the command line arguments to the running instance退出新实例.

原文地址:https://www.jb51.cc/csharp/243659.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐