[英]Context Menu item not showing
I am trying to place a new Menuitem in Explorer context menu and I cannot get it to work. 我试图在资源管理器上下文菜单中放置一个新的Menuitem,但无法使其正常工作。
I am not getting any exceptions or error messages and I've set breakpoints and they're not being hit. 我没有收到任何异常或错误消息,并且已经设置了断点,并且没有被击中。 And I've searched the registry and it's not there. 而且我已经搜索了注册表,但它不存在。 What am I doing wrong? 我究竟做错了什么?
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);
}
}
}
}
Run your app as admin. 以管理员身份运行您的应用。 Making changes to the register may require admin rights. 更改注册可能需要管理员权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.