Archive: OT: registering a shell extension


OT: registering a shell extension
  i would like to register an EXTENSION-SPECIFIC shell extension to a right-click menu; namely, when one right-clicks on a .iso image i would like a 'burn image' option which would execute the app i want (cdrecord).

i traced around misc existing ones in my registry, but they all seem to reference specifically-named 'keys' like {1111-0000-AAAA-FFFF-DDDD}, so i'm a bit lost. i've got the sample listed below, but i don't know how to generate a UNIQUE key for any system.

- edit:

i got even further now, found i can use uuidgen or guidgen (wonder what the difference is) from the ms platform sdk to make these. is this my only way? would i have to include this in my installer, pipe the output to a file, read in the file, etc?

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.zzz]
@ = "zzzfile"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\zzzfile]
@ = "a zzz file"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\zzzfile\shellex\
ContextMenuHandlers\{11111...}]
@ = ""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{11111...}]
@ = "a zzz file"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{11111...}\InProcServer32]
@ = "c:\\myshellextension.dll"
"ThreadingModel" = "Apartment"

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\
Shell Extensions\Approved]
"{11111...}" = "a zzz file handler"


To create a file association, do the following in NSIS:

WriteRegStr HKCR ".xxx" "" "MyApp.Document"

>WriteRegStr HKCR "MyApp.Document" "" "MyApp Document"
>WriteRegStr HKCR "MyApp.Document\\shell\\open\\command" "" 'c:\\LongPathname\\Myapp.exe "%1"'
Replace "MyApp.Document" by an identifier for the association, usually applicationname+".Document"
Replace ".xxx" with the extention (don't forget the '.' in front of it)
Replace "MyApp Document" by a title for the association.
Replace "c:\LongPathname\Myapp.exe %1" by your program path (don't forget the '%1' after it, else the filename will not be passed trough to the program).

To create an extra submenuitem, use this code:
WriteRegStr HKCR "MyApp.Document\\shell\\menuitem name\\command" "" 'c:\\LongPathname\\2ndMyapp.exe "%1"' 

This line is basically the same as the last line of my other code, but i've replaced "open" in the keyname with "menuitem name". Tou can use any name for a menu, just replace "menuitem name" with it, for example: "Burn this CD".

You can also replace the "open" in "MyApp.Document\shell\open\command" to add more commands such as burn for example. NSIS does this (compile nsi script) so you can find an example in makensis.nsi.

If you want to create a more serious shell extension look at:

http://www.codeproject.com/shell/shellextguideindex.asp


KiCHiK, you repeated me. The last two lines of my post said the same. :p


Oops :)


wow awesome!

is there a way to pipe commands in this? like blah blah blah blah %1;pause, to add a pause after it?

i know i can use a batch file for that, but it seems a bit unclean


I don't think so. Windows does not support such a sophisticated command line parsing. You can write a little silent NSIS installer to do that. I wouldn't recommend on a batch file because it will open up a DOS window.


ok what about the HKCR\*\shellex\ContextMenuHandlers? it looks like those require guids

this also makes me wonder how winamp2 has the right-click play/enqueue in winamp shell extensions without being present in this key


Those keys relate to more serious shell extension with sub menus, drag & drop suppport and more. The link I gave above is about those extensions.