您的位置:首页 > 其它

Windows Explorer中对所选文件增加右键菜单并关联自己程序的例子

2011-05-26 18:01 966 查看
为选中文件注册右键菜单

private void registerFile()

{ if (this.txtName.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.txtName.Text); RegistryKey cmd = custome.CreateSubKey("command"); //下边为你想关联的程序可以是任何语言写的任何程序

//D:\Projects\ContextMenu\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe string executePath = @txtAppPath.Text; //Application.ExecutablePath

//%1 代表所选文件全路径 如c:\abcd.pdf

cmd.SetValue("", executePath + " %1"); cmd.Close(); custome.Close(); shell.Close(); MessageBox.Show("Register sucessfully!", "Notification"); //} }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐