Shell context menu sample in C#

Shell context menu sample in C#  

A sample how to show a shell context menu in your own application. Not very well commented or completely tested but it works! I didn't do all the work myself and here are links to projects/articles I used parts from. 

Based on FileBrowser in C# from Explorer Context Menu, Hooking class taken from MSDN Magazine Cutting Edge column.

Add an entry to Explorer context menu easily – How to add them ?

 

 

 Add items to Windows Explorer Shell context menu with Explorer Shell Context Menu

 

  Add items to Windows Explorer Shell context menu easily with Explorer Shell Context Menu. This powerful .Net component for your own, custom items adding to Windows Explorer Shell context menu will append all your custom entries to the Windows Explorer Shell context menu. This .Net component with full C# and VB.NET support include detailed C# / VB.NET samples, tutorials and support all you may need to add your items to context menu :

  • Add items to Windows Explorer Shell context menu to be shown on any Windows operating system (all OS are supported – Windows XP, Vista, Windows x64 of all types , etc.)
  • Add all your items to Windows Explorer Shell context menu to be shown in any way - with your custom caption and your custom icon, as separator or sub-menu
  • Add items to Windows Explorer Shell context menu to be shown for all files or shown only for computer files of particular type (for example, only for .DOC , .MP3,.WMA,.AAC , .MPG media files)
  • Add your program entries to Windows Explorer Shell context menu, sub-menus, sub-sub-menus, sub-menus of unlimited depth and even much more


Windows Explorer Shell Context Menu - is a .Net framework component that support all you need to insert all your application items to the Windows Explorer Shell context menu - in a fast and easy way. Add all your entries to Explorer context menu right now – fast and exactly as you want :

 Adding items To Explorer Context Menu very easy with Windows Explorer Shell Context Menu

 

This sample C# code demonstrates how to add custom entries to Windows Explorer Shell context menu, this method works only for Windows 95 / Windows 98 (not on XP, Vista, x64 - 64-bit Windows), so if you want to addentries to Windows Shell context menu you should use, according to Microsoft guidelines, appropriate .Net component - Windows Context Menu. Comments on how to use inside the file.

Notes:
Thank you sooooo much, i've been all around the net trying to do this for soooo long. u have helped me tremendously. thanks a million. God bless you Smile
Edit:
i have a small question , is there a way to get the context menu for the drives and my computer?
Edit:
hi again
i tried modifying the code so i could pass the csidl then get ppidl using SHGetSpecialFolderLocation but it throws nullRefrence exception on oParentFolder in GetContextMenuInterfaces
so i used:
IShellFolder oDesktopFolder = GetDesktopFolder();
then used GetContextMenuInterfaces(oDesktopFolder, _arrPIDLs))
now using SHGetSpecialFolderLocation:
[DllImport("Shell32", EntryPoint = "SHGetSpecialFolderLocation",
ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern Int32 SHGetSpecialFolderLocation(
IntPtr hwndOwner, CSIDL nFolder, out IntPtr ppidl);
and the CSIDL enum:


public enum CSIDL
{

ADMINTOOLS = 0x30,
ALTSTARTUP = 0x1d,
APPDATA = 0x1a,
BITBUCKET = 10,
CDBURN_AREA = 0x3b,
COMMON_ADMINTOOLS = 0x2f,
COMMON_ALTSTARTUP = 30,
COMMON_APPDATA = 0x23,
COMMON_DESKTOPDIRECTORY = 0x19,
COMMON_DOCUMENTS = 0x2e,
COMMON_FAVORITES = 0x1f,
COMMON_MUSIC = 0x35,
COMMON_PICTURES = 0x36,
COMMON_PROGRAMS = 0x17,
COMMON_STARTMENU = 0x16,
COMMON_STARTUP = 0x18,
COMMON_TEMPLATES = 0x2d,
COMMON_VIDEO = 0x37,
CONTROLS = 3,
COOKIES = 0x21,
DESKTOP = 0,
DESKTOPDIRECTORY = 0x10,
DRIVES = 0x11,
FAVORITES = 6,
FLAG_CREATE = 0x8000,
FONTS = 20,
HISTORY = 0x22,
INTERNET = 1,
INTERNET_CACHE = 0x20,
LOCAL_APPDATA = 0x1c,
MYDOCUMENTS = 12,
MYMUSIC = 13,
MYPICTURES = 0x27,
MYVIDEO = 14,
NETHOOD = 0x13,
NETWORK = 0x12,
PERSONAL = 5,
PRINTERS = 4,
PRINTHOOD = 0x1b,
PROFILE = 40,
PROFILES = 0x3e,
PROGRAM_FILES = 0x26,
PROGRAM_FILES_COMMON = 0x2b,
PROGRAMS = 2,
RECENT = 8,
SENDTO = 9,
STARTMENU = 11,
STARTUP = 7,
SYSTEM = 0x25,
TEMPLATES = 0x15,
WINDOWS = 0x24

}
u could retreive the context menu of various shell item. Enjoy!