开发者

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

开发者 https://www.devze.com 2022-12-13 20:30 出处:网络
I am writing a C# application and it takes files as argument, I added it to shell context menu with code listed below;

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

if开发者_Python百科 (((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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消