如何將項目新增至資料夾的上下文功能表?

如何將項目新增至資料夾的上下文功能表?

我知道如何在單擊實際資料夾時添加上下文選單:

[HKEY_CLASSES_ROOT\Directory\shell\commandNameHere]

但是什麼都不點擊怎麼辦在資料夾中

就像我在桌面上建立一個新資料夾,雙擊進入該資料夾,然後右鍵單擊任何內容(該資料夾為空),現在我希望我的上下文功能表出現在這種情況下。

答案1

對於任何有興趣的人,這裡是.reg將此功能添加到 Windows 上下文功能表的檔案:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Shell]
@="none"
[HKEY_CLASSES_ROOT\Directory\shell\gitBashHere]
[HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere]
"Icon"="C:\\icons\\git-gui.ico"
"MUIVerb"="git bash here"
"Position"="bottom" 
[HKEY_CLASSES_ROOT\Directory\shell\gitBashHere\command] 
[HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere\command]
@="C:\\Program Files\\Console2\\Console.exe -d %v"

(取自xero 的評論

這會在名為「git bash here」的上下文選單中新增一個帶有圖示的命令,該圖示會開啟控制台。

該命令添加在以下兩者:

  • HKEY_CLASSES_ROOT\Directory\shell,右鍵單擊資料夾時的上下文選單
  • HKEY_CLASSES_ROOT\Directory\background,在資料夾中右鍵單擊“背景”空白區域時的上下文選單

答案2

void WriteContextMenu(LPSTR key, LPSTR value) {

HKEY hkey=0; DWORD disp;

if(RegCreateKeyEx(HKEY_CLASSES_ROOT, key, 0, NULL, REP_OPTION_NON_VOLATILE, KEY_WRITE,NULL, &hkey, &disp)!=ERROR_SUCCESS) 

{

     if(RegOpenKey(HKEY_CLASSES_ROOT,key,&hkey)!=ERROR_SUCCESS)
    {   

      cout<<"Unable to open Registry"<<key;

        }

}if(RegSetValueEx(hkey,TEXT(""),0,REG_SZ,(LPBYTE)value, strlen(value)*sizeof(char))!=ERROR_SUCCESS)

{

   RegCloseKey(hkey);

       cout<<"Unable to set Registry Value ";

} else{

   cout<<value<<" value has set"<<endl;
}
}int main(){LPSTR key="Folder\\shell\\Testing_App"; 

 LPSTR valueKey="Menu_Title";

 LPSTR Subkey="Folder\\shell\\Testing_App\\command";


/*Here put the path or action you want to perform like you want to
    open cmd  on your context menu so the value id */

    LPSTR valueSubKey="cmd.exe";

    WriteContextMenu(key, ValueKey); 
    WriteContextMenu(Subkey, ValueSubKey);

return 0;}

答案3

這是適用於所有上下文選單的一種解決方案。

https://stackoverflow.com/questions/20449316/how-add-context-menu-item-to-windows-explorer-for-folders/20458056#20458056

但是,如何將多個目錄或文件作為參數傳遞到此上下文選單(如%1)只需要一個,當我們ctrl+單擊多個文件時,它會多次打開可執行文件,而不是將所有目錄或文件作為參數發送。

相關內容