Windows Context Menu (右鍵選單)

右鍵選單在 Windows 中佔有相常重要的地位,許多應用程式,如 UltraEdit, WinZip 等都會將他們的功能加到右鍵選單中方便使用者操作。但有時我們卻不一定喜歡這些應用程式所加的右鍵選單,或是我們也想把一些操作加入右鍵選單中。本篇我們就來探討如何修改 Windows 右鍵選單。

右鍵選單主要是被定義在 Registry 中,但 Windows 並沒有一個統一的地方集中設定右鍵選單的內容,而是分散在各個操作目標子機碼的 shell, 及 ShellEx\ContextMenuHandlers 子機碼中

HKEY_CLASSES_ROOT
   subkey
       shell

HKEY_LOCAL_MACHINE
    SOFTWARE
        Classes
           subkey
               shell

HKEY_CURRENT_USER
    SOFTWARE
        Classes
           subkey
               shell

上面的操作目標子機碼 subkey,一般而言,如以下表格所列:
SubkeyDescription
*All files
AllFileSystemObjectsAll files and file folders
FolderAll folders
DirectoryFile folders
Directory\Background File folder background
Drive All drives in MyComputer, such as "C:\"
NetworkEntire network (under My Network Places)

舉例來說,對 Folder, Directory 的右鍵選單操作會被定義在:
  • [HKLM\Folder\Shell\]
  • [HKLM\Folder\ShellEx\ContextMenuHandlers\]
  • [HKLM\Directory\Shell\]
  • [HKLM\Directory\ShellEx\ContextMenuHandlers\]
但是 AllFilesystemObjects 也是會對 Folder, Directory 有影響
  • [HKLM\AllFilesystemObjects\shell\]
  • [HKLM\AllFilesystemObjects\shellex\ContextMenuHandlers\]
所以當我們要刪除 Folder 的右鍵選單時就必須從這些地方去找。


新增右鍵選單項目


我們用一個例子來說明如何新增右鍵選單項目

新增 "Command Prompt Here" (開啟命令視窗)到右鍵選單

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\command prompt]
@="Command Prompt Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\command prompt\command]
@="cmd.exe"

我們在上面的 registry 設定中,在 shell 子機碼下面加入了一個我們自訂的子機碼 command prompt 及它所要執行的命令:子機碼 command。新增完後,在 file exploer (檔案總管)的空白區域開啟右鍵選單,我們就會發現剛剛加的"Command Prompt Here"的選項出現在右鍵選單之中。

事實上 Vista 和 Win7 早就有這個功能,檢查一下
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\cmd
就會發現類似的機碼已經存在了,但是卻多了兩個字串值
  • Extended
  • NoWorkingDirectory
只要把 Extended 整個刪除,這個功能就會出現在右鍵選單之中。

Reference:

0 意見 :: Windows Context Menu (右鍵選單)

張貼留言