加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:27:46 所属栏目:百科 来源:网络整理
导读:我正在编写一个C#应用程序,它将文件作为参数,我将它添加到 shell上下文菜单中,代码如下所示; if (((CheckBox)sender).CheckState == CheckState.Checked) { RegistryKey key = Registry.CurrentUser.OpenSubKey("SoftwareClasses*shell" + KEY_NAME
我正在编写一个C#应用程序,它将文件作为参数,我将它添加到 shell上下文菜单中,代码如下所示;
if (((CheckBox)sender).CheckState == CheckState.Checked)
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("SoftwareClasses*shell" + KEY_NAME + "command");

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

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

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

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读