Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 上下文菜单项不显示_C#_.net_Winforms_Winapi_Registry - Fatal编程技术网

C# 上下文菜单项不显示

C# 上下文菜单项不显示,c#,.net,winforms,winapi,registry,C#,.net,Winforms,Winapi,Registry,我试图在资源管理器上下文菜单中放置一个新的菜单项,但无法使其正常工作 我没有收到任何异常或错误消息,我设置了断点,它们没有被击中。我搜索了注册表,但它不在那里。我做错了什么 private const string MenuName = "Folder\\shell\\NewMenuOption"; private const string Command = "Folder\\shell\\NewMenuOption\\command"; private void F

我试图在资源管理器上下文菜单中放置一个新的菜单项,但无法使其正常工作

我没有收到任何异常或错误消息,我设置了断点,它们没有被击中。我搜索了注册表,但它不在那里。我做错了什么

    private const string MenuName = "Folder\\shell\\NewMenuOption";
    private const string Command = "Folder\\shell\\NewMenuOption\\command";

    private void Form1_Shown(object sender, EventArgs e)
    {
        using(var folder = new FolderBrowserDialog())
        {
            if(folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Properties.Settings.Default.ArchivePath = folder.SelectedPath;
                Properties.Settings.Default.Save();

                RegistryKey regmenu = null;
                RegistryKey regcmd = null;
                try
                {
                    regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
                    if (regmenu != null)
                        regmenu.SetValue("", "Archive");
                    regcmd = Registry.ClassesRoot.CreateSubKey(Command);
                    if (regcmd != null)
                        regcmd.SetValue("", Environment.CurrentDirectory + @"\Archiver.exe");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.ToString());
                }
                finally
                {
                    if (regmenu != null)
                        regmenu.Close();
                    if (regcmd != null)
                        regcmd.Close();
                }
            }
            else
            {
                if(MessageBox.Show("In order to use Archiver, you must first specify where your archive is. Do you want to continue?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                {
                    Application.Restart();
                }
                else
                {
                    this.Dispose(true);
                }
            }
        }
    }
以管理员身份运行应用程序。 更改注册表可能需要管理员权限。

以管理员身份运行应用程序。
更改注册表可能需要管理员权限。

以管理员身份运行?+你在哪里设置了断点?@BramVanStrydonck,嗯,我不确定在哪里设置断点,因为我认为代码很好,所以我到处设置断点!我会试着当管理员。啊。这是一个管理员帐户-它不应该要求我作为管理员运行一个该死的应用程序!那么你的代码甚至还没有到达using语句?@BramVanStrydonck我只是以管理员的身份运行了这个应用程序,它工作了。真不敢相信我竟然忘了当管理员。非常感谢你的帮助!以管理员身份运行?+你在哪里设置了断点?@BramVanStrydonck,嗯,我不确定在哪里设置断点,因为我认为代码很好,所以我到处设置断点!我会试着当管理员。啊。这是一个管理员帐户-它不应该要求我作为管理员运行一个该死的应用程序!那么你的代码甚至还没有到达using语句?@BramVanStrydonck我只是以管理员的身份运行了这个应用程序,它工作了。真不敢相信我竟然忘了当管理员。非常感谢你的帮助!可能需要也可能需要。因为任何改变系统的操作都必须在完全信任模式下运行。可能需要也可能需要。因为任何改变系统的操作都必须在完全信任模式下运行。