现在的位置: 首页 > 综合 > 正文

(目录或)文件右键菜单增加项目,inno,c#

2012年08月30日 ⁄ 综合 ⁄ 共 3390字 ⁄ 字号 评论关闭
在系统右键菜单增加项目



/// 本质的内容:
Windows Registry Editor Version 5.00
// 点击所有文件类型的时候显示菜单
[HKEY_CLASSES_ROOT/*/shell/Simple Context Menu/command]
@="/"C://temp//SimpleContextMenuProject//SimpleContextMenu//bin//Debug//SimpleContextMenu.exe/" /"%L/""

// 点击目录的时候显示菜单
[HKEY_CLASSES_ROOT/Directory/shell/Simple Context Menu/command]
@="/"C://temp//SimpleContextMenuProject//SimpleContextMenu//bin//Debug//SimpleContextMenu.exe/" /"%L/""



////// inno 打包脚本
[Registry]
; [HKEY_CLASSES_ROOT/*/shell/Simple Context Menu/command]
; @="/"C://temp//SimpleContextMenuProject//SimpleContextMenu//bin//Debug//SimpleContextMenu.exe/" /"%L/""
Root: HKCR; Subkey: "*/shell/send to xxx/command"; ValueType: string; ValueData: "{app}/xxx.exe ""%1"""; Flags: uninsdeletekeyifempty
;[HKEY_CLASSES_ROOT/Directory/shell/Simple Context Menu/command]
;@="/"C://temp//SimpleContextMenuProject//SimpleContextMenu//bin//Debug//SimpleContextMenu.exe/" /"%L/""
Root: HKCR; Subkey: "Directory/shell/send to xxx/command"; ValueType: string; ValueData: "{app}/xxx.exe ""%1"""; Flags: uninsdeletekeyifempty

--20091201 适应key名称修改的情况!
Root: HKCR; Subkey: "*/shell/Send to xxx"; Flags: uninsdeletekey
Root: HKCR; Subkey: "*/shell/Send to xxx/command"; ValueType: string; ValueData: "{app}/xxx.exe ""%1"""; Flags: uninsdeletekey
Root: HKCR; Subkey: "Directory/shell/Send to xxx"; Flags: uninsdeletekey
Root: HKCR; Subkey: "Directory/shell/Send to xxx/command"; ValueType: string; ValueData: "{app}/xxx.exe ""%1"""; Flags: uninsdeletekey
///// c#实现
// Sample application that demonstrates a simple shell context menu.
// Ralph Arvesen (www.vertigo.com / www.lostsprings.com)

using System;
using System.Diagnostics;
using Microsoft.Win32;

namespace SimpleContextMenu
{
	/// 
	/// Register and unregister simple shell context menus.
	/// 
	static class FileShellExtension
	{
		/// 
		/// Register a simple shell context menu.
		/// 
		/// 

The file type to register.
		/// 

Name that appears in the registry.
		/// 

Text that appears in the context menu.
		/// 

Command line that is executed.
		public static void Register(
			string fileType, string shellKeyName, 
			string menuText, string menuCommand)
		{
			Debug.Assert(!string.IsNullOrEmpty(fileType) &&
				!string.IsNullOrEmpty(shellKeyName) &&
				!string.IsNullOrEmpty(menuText) && 
				!string.IsNullOrEmpty(menuCommand));
			
			// create full path to registry location
			string regPath = string.Format(@"{0}/shell/{1}", fileType, shellKeyName);

			// add context menu to the registry
			using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(regPath))
			{
				key.SetValue(null, menuText);
			}
			
			// add command that is invoked to the registry
			using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(
				string.Format(@"{0}/command", regPath)))
			{				
				key.SetValue(null, menuCommand);
			}
		}
        private static string DirectoryFileType = "Directory";
        public static void RegisterDir(
            string shellKeyName,
            string menuText, string menuCommand)
        {
            Register(DirectoryFileType, shellKeyName, menuText, menuCommand);
        }
		/// 
		/// Unregister a simple shell context menu.
		/// 
		/// 

The file type to unregister.
		/// 

Name that was registered in the registry.
		public static void Unregister(string fileType, string shellKeyName)
		{
			Debug.Assert(!string.IsNullOrEmpty(fileType) &&
				!string.IsNullOrEmpty(shellKeyName));

			// full path to the registry location			
			string regPath = string.Format(@"{0}/shell/{1}", fileType, shellKeyName);

			// remove context menu from the registry
			Registry.ClassesRoot.DeleteSubKeyTree(regPath);
		}
        public static void UnregisterDir(string shellKeyName)
        {
            Unregister(DirectoryFileType, shellKeyName);
        }
	}

}


// 调用
				// register the context menu
				FileShellExtension.Register(Program.FileType,
					Program.KeyName, Program.MenuText,
					menuCommand);
                
				FileShellExtension.Register("Directory",
					Program.KeyName, Program.MenuText,
					menuCommand);

抱歉!评论已关闭.