簡體   English   中英

如何將項目添加到窗口的上下文菜單中[僅適用於pdf文件和doc文件]

[英]How to add item into window's Context menu [only for pdf file and doc file]

我為虛擬打印機創建了一個c#應用程序,但現在我正在尋找啟動我的應用程序,同時右鍵單擊任何.pdf文件或任何.doc文件

總之,我想在窗口的上下文菜單中添加項目,但僅限於.pdf文件和.doc文件。

請建議我如何實現它。

提前致謝。

要了解要修改/添加的鍵,請在此處查看接受的答案: 僅針對特定文件類型向Windows上下文菜單添加菜單項

要使用C#添加密鑰,請使用RegistryKey對象

string[] exts = {".pdf", ".doc"};
foreach (string ext in exts)
{
    RegistryKey _key = Registry.ClassesRoot.OpenSubKey($"HKEY_CLASSES_ROOT\\{ext}\\shell", true);
    RegistryKey newkey = _key.CreateSubKey("Use Virtual Printer");

    RegistryKey subNewkey = newkey.CreateSubKey("Command");
    subNewkey.SetValue("", "C:\\yourApplication.exe");
    subNewkey.Close();

    newkey.Close();
    _key.Close();
} 

修改自如何將上下文菜單項添加到Windows資源管理器中的文件夾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM