gpt4 book ai didi

c# - 如何将项目添加到窗口的上下文菜单中[仅适用于 pdf 文件和 doc 文件]

转载 作者:可可西里 更新时间:2023-11-01 09:28:29 26 4
gpt4 key购买 nike

我为虚拟打印机创建了一个 c# 应用程序,但现在我正在寻找在右键单击任何 .pdf 文件或任何 .doc 文件时启动我的应用程序

简而言之,我想在窗口的上下文菜单中添加项目,但仅限于 .pdf 文件和 .doc 文件。

请建议我如何实现它。

提前致谢。

最佳答案

要知道要修改/添加哪些键,请在此处查看已接受的答案: Add menu item to windows context menu only for specific filetype

要使用 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();
}

修改自 How add context menu item to Windows Explorer for folders

关于c# - 如何将项目添加到窗口的上下文菜单中[仅适用于 pdf 文件和 doc 文件],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32780122/

26 4 0