0
我想在資源管理器的上下文菜單中放置一個新的Menuitem,我無法讓它工作。上下文菜單項不顯示
我沒有收到任何異常或錯誤消息,並且設置了斷點,但它們沒有被擊中。我搜索了註冊表,它不在那裏。我究竟做錯了什麼?
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,好吧,我不確定在哪裏設置它們,因爲我認爲代碼非常好,所以我將它們設置在任何地方! – uSeRnAmEhAhAhAhAhA
我將以管理員身份嘗試。哎呀。這是一個管理員帳戶 - 它不應該要求我以管理員身份運行一個該死的應用程序! – uSeRnAmEhAhAhAhAhA