zoukankan      html  css  js  c++  java
  • [转]C# 注册自己的右键菜单 (文件夹/文件)

    一个小小的例子, 演示了如何通过操作注册表, 添加自己的文件或文件夹右键菜单.

    // 添加到注册表
    private void btnRegister_Click(object sender, EventArgs e)
    {
    if (this.tbMenuTitle.Text.Length == 0) return;

    // 注册到文件
    if (this.ckRegToFile.Checked)
    {
    RegistryKey shell
    = Registry.ClassesRoot.OpenSubKey("*", true).OpenSubKey("shell", true);
    if (shell == null) shell = Registry.ClassesRoot.OpenSubKey("*", true).CreateSubKey("shell");
    RegistryKey custome
    = shell.CreateSubKey(this.tbMenuTitle.Text);
    RegistryKey cmd
    = custome.CreateSubKey("command");
    cmd.SetValue(
    "", Application.ExecutablePath + " %1");
    cmd.Close();
    custome.Close();
    shell.Close();
    }

    // 注册到文件夹
    if (this.ckRegToDir.Checked)
    {
    RegistryKey shell
    = Registry.ClassesRoot.OpenSubKey("directory", true).OpenSubKey("shell", true);
    if (shell == null) shell = Registry.ClassesRoot.OpenSubKey("directory", true).CreateSubKey("shell");
    RegistryKey custome
    = shell.CreateSubKey(this.tbMenuTitle.Text);
    RegistryKey cmd
    = custome.CreateSubKey("command");
    cmd.SetValue(
    "", Application.ExecutablePath + " %1");
    cmd.Close();
    custome.Close();
    shell.Close();
    }
    MessageBox.Show(
    "注册成功!", "提示");
    }

    // 反注册
    private void btnUnRegister_Click(object sender, EventArgs e)
    {
    RegistryKey shell
    = Registry.ClassesRoot.OpenSubKey("*", true).OpenSubKey("shell", true);
    if (shell != null) shell.DeleteSubKeyTree(this.tbMenuTitle.Text);

    shell
    = Registry.ClassesRoot.OpenSubKey("directory", true).OpenSubKey("shell", true);
    if (shell != null) shell.DeleteSubKeyTree(this.tbMenuTitle.Text);

    shell.Close();

    MessageBox.Show(
    "反注册成功!", "提示");
    }



    另外一个例子codeproject上的:

     http://www.codeproject.com/KB/cs/appendmenu.aspx?msg=3335190#xx3335190xx

  • 相关阅读:
    haproxy教程
    haproxy和keepalived的理解(转载)
    redis集群搭建_超详细
    磁盘IO过高时的参考
    tomcat优化
    MYSQL数据库的主从复制
    k8s学习笔记-etcd介绍和集群搭建
    python排序算法二---冒泡排序
    Python排序算法一—快速排序
    python:如何判断字典a在字典b
  • 原文地址:https://www.cnblogs.com/jjj250/p/2059046.html
Copyright © 2011-2022 走看看