3

I created one c# application for virtual printer but now I am looking for start my application while right clicking on any .pdf file or any .doc file

in short i want to add item in window's context menu but only for .pdf file and .doc file.

please suggest me how to achieve it.

thanks in advance.

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
Darshan Faldu
  • 1,471
  • 2
  • 15
  • 32

1 Answers1

2

To know what keys to modify/add, see the accepted answer here: Add menu item to windows context menu only for specific filetype

To add the keys using C#, use a RegistryKey object

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

modified from How add context menu item to Windows Explorer for folders

Moe
  • 462
  • 2
  • 16
  • 1
    Please quote the relevant sections from your links and be sure to include an explanation in your answers. – nloewen Feb 27 '17 at 15:45