Shell Context Menu

July 5th, 2007 by Andrew Vos

EDIT: There is a newer version here!

Some VB.NET 2005 code to display the Shell Context Menu for file system objects.

  • Supports multiple files.
  • Supports proper drawing of Open With and Send To menus.
  • Supports Special Folders.

Any problems with the code or bug fixes please don’t hesitate to complain.

Source code is here

Shell Context Menu

Popularity: 20% [?]

Posted in Code Projects

RSS feed | Trackback URI

16 Comments »

Comment by John Subscribed to comments via email
2007-07-16 11:55:59
Get your own Gravatar here!

Thanks, I’ve been looking for this all over!

 
Comment by Andrew Subscribed to comments via email
2007-07-16 12:01:27
Get your own Gravatar here!

Pleasure

 
Comment by .NETguy
2007-07-16 12:04:28
Get your own Gravatar here!

Thanks for the code!

 
Comment by Martin Subscribed to comments via email
2007-09-30 01:48:11
Get your own Gravatar here!

Hi
Fantastic code, just what I was after.

Is it possible to add custom items to the menu and return a result based on the custom item that was selected ?

A few pointers in the right direction would be extremely helpful.

Thanks again
Martin

 
Comment by Andrew Vos Subscribed to comments via email
2007-09-30 23:39:49
Get your own Gravatar here!

That’s totally possible, although I haven’t ever done it before.

I have seen numerous examples on codeproject etc.

They would only show up in menus that you show yourself though. There are plenty examples showing how to add an item to the default menu though. The most simple method is a registry hack.

 
Comment by Donny Subscribed to comments via email
2007-12-01 21:00:49
Get your own Gravatar here!

This piece of code is awesome! There were a lot of commercial ActiveX and OCX controls that did a lot more than just provide explorer context menu, but menu is the only thing I need.

Thank you!

Comment by Andrew Vos Subscribed to comments via email
2007-12-02 10:42:28
Get your own Gravatar here!

Glad you found some use of it!

 
 
Comment by Teo Subscribed to comments via email
2008-03-07 22:26:58
Get your own Gravatar here!

Thank you for the code. It works like a charm.

Teo

Comment by Andrew Vos Subscribed to comments via email
2008-03-10 13:43:36
Get your own Gravatar here!

Glad it worked for you.

 
 
Comment by JoeAndLester Subscribed to comments via email
2008-04-22 19:56:24
Get your own Gravatar here!

Any idea why the “Rename” option isn’t in the menu?

Comment by Andrew Vos Subscribed to comments via email
2008-04-22 20:32:18
Get your own Gravatar here!

I think it’s something to do with some flags in one of the calls.

Please remind me of the problem if you find it, and I’ll update the code.

Otherwise, I’ll take a look tomorrow maybe.

 
 
Comment by JoeAndLester Subscribed to comments via email
2008-04-22 21:43:35
Get your own Gravatar here!

Thanks for the pointer. In the call to QueryContext menu the uFlags parameter must have the CMF_CANRENAME bit (&H10 in VB) set for the Rename option to appear. Please not that code EXTERNAL to the code provided here must handle this by examining the return code.

On another note, there is something strange with the code that sets uFlags to 256 when a shift key is pressed. If I need to figure this out I’ll post again.

Comment by Andrew Vos Subscribed to comments via email
2008-04-23 07:37:13
Get your own Gravatar here!

Yeah, you’re gonna have to take the return code and code a replacement for the rename dialog.

Not very good cause you’ll have to hard code Rename. Seems like a step backwards to me.

 
Comment by Andrew Vos Subscribed to comments via email
2008-04-23 07:46:14
Get your own Gravatar here!

CMF_EXTENDEDVERBS
This flag is set when the calling application wants extended verbs. Normal verbs are displayed when the user right-clicks an object. To display extended verbs, the user must right-click while pressing the SHIFT key.

Got that from MSDN. Should have added a constant for that, sorry. Quite cryptic.

 
 
Comment by SJoachimsthaler Subscribed to comments via email
2009-07-08 16:38:01
Get your own Gravatar here!

is it possible to display the contextmenu, which appears by clicking in the empty space in windows-explorer?

 
Comment by TheRoughGuy
2010-01-24 11:31:02
Get your own Gravatar here!

Thanks A Lot for the code…

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word