none
给zip文件添加右键菜单失败 RRS feed

  • 问题

  • 我通过以下方式给.zip文件添加右键菜单,在注册表中发现已经添加了数据,但是在资源管理器中依然看不到这个右键菜单。

    代码和注册表中的截图如下。

    /// <summary>
            /// 注册本应用右键菜单 文件拓展名对应extract右键菜单
            /// </summary>
            public static void RegisterToUnZip()
            {
                try
                {
                    // file type to register
                    string FileType = "";

                    // context menu name in the registry
                    const string KeyName = "UnZip";

                    // context menu text
                    const string MenuText = "Extract";

                    string[] FileTypes = { ".zip"};        

                        FileType = ".zip";

                        // full path to self, %L is placeholder for selected file
                        // if .pdf add -extfind Doxillion before "%L"
                        string menuCommand = "";

                        menuCommand = string.Format(
                            "\"{0}\" \"%L\"", System.Windows.Forms.Application.ExecutablePath);


                        // register the context menu
                        FileShellExtension.Register(FileType,
                            KeyName, MenuText,
                            menuCommand);

                }
                catch (Exception ex)
                {
                    string sEX = ex.ToString();
                }
            }

    /// <summary>
      /// Register a simple shell context menu.
      /// </summary>
      /// <param name="fileType">The file type to register.</param>
      /// <param name="shellKeyName">Name that appears in the registry.</param>
      /// <param name="menuText">Text that appears in the context menu.</param>
      /// <param name="menuCommand">Command line that is executed.</param>
      public static void Register(
       string fileType, string shellKeyName,
       string menuText, string menuCommand)
      {
       Debug.Assert(!string.IsNullOrEmpty(fileType) &&
        !string.IsNullOrEmpty(shellKeyName) &&
        !string.IsNullOrEmpty(menuText) &&
        !string.IsNullOrEmpty(menuCommand));
       
       // create full path to registry location
       string regPath = string.Format(@"{0}\shell\{1}", fileType, shellKeyName);

       // add context menu to the registry
       using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(regPath))
       {
        key.SetValue(null, menuText);
       }
       
       // add command that is invoked to the registry
       using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(
        string.Format(@"{0}\command", regPath)))
       {    
        key.SetValue(null, menuCommand);
       }
      }

    2013年10月3日 10:26

答案

  • 你好:

    不是在.zip这个子项下面,这个下面不存在shell这个subkey,自己建的是不起作用的。

    应该在CompressedFolder下面的shell下建立自定义的右键快捷方式:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年10月7日 6:09
    版主

全部回复

  • 你先移除Try……Catch块,然后F5调试程序,是否有异常产生?

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    2013年10月3日 10:44
    版主
  • 你先移除Try……Catch块,然后F5调试程序,是否有异常产生?

    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    没有发生异常,注册表写入成功。请看注册表的截图。

    2013年10月4日 3:02
  • 你好:

    不是在.zip这个子项下面,这个下面不存在shell这个subkey,自己建的是不起作用的。

    应该在CompressedFolder下面的shell下建立自定义的右键快捷方式:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年10月7日 6:09
    版主