天天看點

添加右鍵功能到系統菜單

好久沒有記錄一些東西了,現整理了一點添加右鍵菜單到系統菜單裡,并讀取出所選中的檔案路徑,友善大家,謝謝

private void button1_Click(object sender, EventArgs e)

{

string menuName = "測試";

//注冊到所有檔案

RegistryKey shell = Registry.ClassesRoot.OpenSubKey(@"*/shell", true);

RegistryKey custom = shell.CreateSubKey(menuName);

RegistryKey cmd = custom.CreateSubKey("command");

cmd.SetValue("", Application.ExecutablePath + " %1");

cmd.Close();

custom.Close();

shell.Close();

MessageBox.Show("注冊成功!");

}

private void button2_Click(object sender, EventArgs e)

{

string menuName = "測試";

RegistryKey reg = Registry.ClassesRoot.OpenSubKey(@"*/shell", true);

try

{

if (reg != null)

{

Registry.ClassesRoot.DeleteSubKeyTree(@"*/shell/"+menuName);

}

MessageBox.Show("登出成功!");

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

finally

{

reg.Close();

}

具體示例請到下載下傳中心下載下傳http://43720938.download.csdn.net/