Preview Handler Association Editor


I received an email from MSDN Magazine subscriber Oren Novotny thanking me for my preview handler article in the January 2007 issue of MSDN Magazine.  Oren also wondered whether a tool could be written to make it easy to edit preview handler registrations for particular extensions.  For example, what if you wanted to associate the Microsoft Windows TXT Preview Handler with .reg or .h files so that those would be previewable, where they’re not by default.  Or what if you had two different preview handlers for XML files and you wanted to be able to easily switch back and forth between them with relative ease.


As an answer to this, I threw together a Preview Handler Association Editor tool.  When the app loads, it looks to the registry for all registered preview handlers.  It then loops through all classes and extensions in HKCR to see if each has a preview handler registered, and if it does, which.  Once that data is loaded (which on my machine takes approximately a second), the interface displays a combobox allowing you to pick any of the registered preview handlers.  The listbox with checkboxes of classes and extensions is then refreshed to show all of the classes/extensions; those associated with the selected preview handler will be checked.  Checking items that aren’t checked causes them to be immediately associated with the selected preview handler, and unchecking checked items causes them to be immediately unregistered for the selected preview handler.  You can also check the “Only show classes associated with this handler” check box to filter down the list to make it easier to see all of the extensions/classes currently associated with the selected handler. This tools is provided “as is” with no warranties and confers no rights. It’s covered by the Microsoft Permissive License.

PreviewHandlerEditor.zip

Comments (73)

  1. I figure it won’t be long before folks are asking me how to do this. Stephen Toub put up a great article

  2. Oren Novotny says:

    Thanks, it looks great and works really well.

    –Oren

  3. Rodrigo says:

    Hi.

    There is somehow to associate html files with some PreviewHandler? Outlook 2007 is lacking a html PreviewHandler, thats weird.

    tnx.

    PS.: I got a error after associate .htm with MSDN Internet Explorer Preview Handler using this editor.

  4. Are you using RTM of Outlook 2007 on Vista RTM?  It does have a built-in HTML preview handler.

  5. The new Windows Vista preview pane lets you preview files right within the shell, and Outlook 2007 gives

  6. Could you post the source code for this editor?

    It seems to error everytime I try to run it. I am running Vista x64 RTM by the way.

  7. Brian Kudera says:

    Thanks for sharing this handy utility!

    However, when I run the application I do not have the Registered Handler of Microsoft Windows TXT Preview Handler. How do I add this as a handler?

  8. Stephen Toub says:

    I’ve had several requests for the code for the PreviewHandlerAssociationEditor tool I put up a few weeks

  9. Chris, I’ve updated the download with the source for the tool.  If you figure out why it’s not working for you on x64, I’d be very interested in the answer.  I unfortunately don’t have an x64 machine accessible to me at the moment to test it on.

    Brian, what handlers do show up in the combobox?  Are any available?

  10. briankudera says:

    I have the following Registered Handles displaying in the utility:

    Microsoft Office Excel previewer

    Microsoft Office PowerPoint previewer

    Microsoft Office Visio previewer

    Microsoft Office Word previewer

    FYI I am on Win XP Pro

  11. Ah! Yeah, there are differences between Windows Vista and WinXP.  I tried to make it clear in the article, but obviously I could have made it clearer 😉  Vista ships with some preview handlers, as does Office 2007, and the sets they ship with are different.  I believe the TXT preview handler is just in the Vista subset, which would explain why it’s not available to you.

  12. briankudera says:

    ahh ha toub- that probably explains it!

    Sorry, didn’t catch that as the description of this thread. I’ll locate another thread to post my WinXP Pro issues on.

    Thanks!!

    Brian

  13. Los que tienen Office 2007, o probaron las Betas de Office 2007, se pudieron dar cuenta de una excelente…

  14. Los que tienen Office 2007, o probaron las Betas de Office 2007, se pudieron dar cuenta de una excelente

  15. Stephen Toub says:

    John Robbins emailed me tonight to let me know that he found a bug with my PreviewHandlerAssociatedEditor

  16. Helio says:

    This is great – however it crashes when I try to add XML to the TXT handler.

  17. helio says:

    Sorry I misstated really – I get an unhandled exception the gist of it is this:

    System.UnauthorizedAccessException: Access to the registry key ‘HKEY_CLASSES_ROOTXML’ is denied.

    But the app doesn’t crash. However, nor does it create the handler association. I tried running as admin…

  18. You’re selecting the wrong item in the list.  You want ".xml", not "xml".

  19. Wouter Baake says:

    Is there any reason why HTML preview is not supported with Outlook 2007 on Win XP Pro?

    These kind of stupid things are driving me crazy, there’s HTML rendering for messages, but not for attachment previewing, what the hell is that…

  20. Quartz says:

    I have created a Photoshop preview handler based on your brilliant framework and article on MSDN jan 2007

    Photoshop files(PSD) Preview Handler for Windows Vista here

    http://www.codeproject.com/useritems/PhotoshopPreviewHandler.asp

    Do let me know what you think about that

  21. Quartz, that’s awesome!  I’m glad to see that folks like you are picking this up and running with it to create new preview handlers.  I hope the framework was helpful, and please do let me know of any others you create.

  22. Is it possible to use the file previewer component which already installed with Outlook 2007 using C# Windows Form. Basically I want to preview office document inside my application window. It will help me a lot if you send some article/link on the same

  23. It should be possible, but I’ve never tried.  Good luck.

  24. orimarjr69@gmail.com says:

    i have been looking for a dwg. handler for auto cad for almost a week with no success i am not a programmer but have a feeling by the time i find it i would have already written on myself lol. Every architect and engineer could use this but so far does not exist can any body please point me in at least a general direction i which i should be surfing!

  25. As part of my work on the Coding4Fun Developer Kit 2008, I created a WinForm control encapsulating the…

  26. Geoff says:

    I agree with Wouter Baake  why cant i preview a html attachment in outlook 2007 – this seems really crazy!!!

  27. Dane says:

    Thanks.

    .Divx now previews in Vista.

    Regards

    Dane

  28. Wimmme says:

    For PreviewHandlers on XP, look at http://www.azarfamily.org/previewhandlersforwindowsxp

    GIl Azar did an amazing job there !

  29. Colin Walker says:

    Resolved some issues I was having really easily. Thanks 🙂

  30. Does this code work on Vista x64?

  31. One of the cooler Vista features that I’ve started using more often is the File Preview in Windows Explorer.

  32. One of the cooler Vista features that I’ve started using more often is the File Preview in Windows Explorer.

  33. msapc says:

    Thank you for a good program! Already helped me fix some problems after installing one of those handler packs for WinXP.

    One wish – If You could please make some substring search in the extension list, because otherwise looking for the desired filetype is pretty lengthy process.

    Wthat I want is "search" field, where I could enter "pd" (case insensitive) and see only ".*PD.*" stuff, including those long names like "Adobe PDF File" along with simple ".pdf" lines.

  34. kenzy says:

    How about the .rar type files ? I can’t find it after installed winrar. No prog handler found

  35. John Smith says:

    If I preview an Excel file, an instance of Excel.exe is opened that stays open. This prevents me from double clicking an Excel file because the excel.exe that is already running causes Excel to report that Personal.xlsb is in use, so my macros are not available.

    The only way I can use Excel freely is to shut down Explorer after previewing, to kill that first instance of excel.exe, then open Excel, then do File, Open and navigate to the file. Hardly practical!

    Could you suggest a solution?

  36. Amirz says:

    the tool detects only registered preview handler that already exists. Can it add new ones? eg for dwg. thanks

  37. I figure it won’t be long before folks are asking me how to do this. Stephen Toub put up a great article

  38. Preview Handlers for Vista and Outlook 2007

  39. adobe premiere elements tryout serial [URL=http://fokrdarc.ifrance.com/20081130-adobe-premiere.htm]adobe premiere elements tryout serial[/URL] [url=http://fokrdarc.ifrance.com/20081130-adobe-premiere.htm]adobe premiere elements tryout serial[/url] [url]http://fokrdarc.ifrance.com/20081130-adobe-premiere.htm[/url]

  40. newbie says:

    I’m testing out this and the excellent handler framework, and I’ve come across an issue/question. I can’t seem to get jpg/gif/bmp files to preview properly in the code i’m writing, though other file types (office, pdf, etc.) work fine as in the example code. Jpg/Gif/Bmp files preview just fine in the Vista explorer preview pane, so I don’t think there’s any issue in my registry, etc., but I can’t find out what previewer is used for them (none shows in HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPreviewHandlers).

    Any thoughts or guidance on this would be much appreciated!

  41. Stephen … I want to thank you for your excellent contribution to everyone with the fantastic tool …

    I do a lot of web development work and it is fantastic to be able to preview code automatically without having to open up my preferred text editor to view the files (EditPad Pro):) …

    Thank you very much …

    Edward Beckett

  42. Rudy says:

    I can’t download this tool! (404) Please fix it thanx

  43. Willi says:

    Based on your article "View Data Your Way With Our Managed Preview Handler", here a preview handler for .rar file. It can be download at this url http://www.csharpfr.com/codes/PREVIEW-HANDLER-OFFICE-OUTLOOK-2007-10-SUR-FICHIERS_50647.aspx

  44. Hadster says:

    Has anyone figured out how to preview non-".txt" text formats (such as ".bat") with the text handler on XP? The TXT handler does not show up in the list on XP.

  45. Oli says:

    Thank you Steve, it works perfectly for me!

  46. chris says:

    Where can I setup the media player to automatically to a 200% zoom open the video

  47. Bob says:

    Has a way to preview dwg files been discovered yet?

    Thanks

    Bob

  48. Toni says:

    Preview Handler blocking Excel

    If I preview an Excel file, an instance of Excel.exe is opened that stays open. When I want to preview another excel document everything just hangs.

    Csan you help?

  49. Samer says:

    thanks works really well 🙂 I wanted to get previews of flv vids and amr audio

    and it worked 🙂

    thank u

  50. tanguy says:

    hey! I've installed that and associated many extensions to Office Word, however when I try to preview them inside Outlook 2007 (running on Win XP), I still get the "no previewer installed for it" message. Any idea on the cause? thx for your time!

  51. dflag says:

    Solutions to all who have the following two problems:

    1) A System.Security.Exception occurs when running the release-binary outside VS as a non admin on Vista/7.

    Change the line in 'PreviewHandlerRegistryAccessor.cs' that reads:

               using (RegistryKey handlersKey = Registry.LocalMachine.OpenSubKey(BaseRegistryKey, true))

    to

               using (RegistryKey handlersKey = Registry.LocalMachine.OpenSubKey(BaseRegistryKey, false))

    We dont need here writeaccess to the registry!

    2) When previewing DOC/XLS…-files a process "WINWORD.EXE" or "EXCEL.EXE" might stay open either when the program quits or when the handler isnt used anymore. Just add following lines to 'PreviewHandlerHostControl.cs' in the Method 'Generatepreview':

               if (_comInstance != null)

               {

                   ((IPreviewHandler)_comInstance).Unload();

                   Marshal.FinalReleaseComObject(_comInstance); //quits the handler

                   _comInstance = null;

               }

    In order to quit the process on closing the form, you have to add a public method to the PreviewhandlerHostControl that calls FinalReleaseComObject, so everything is cleared.

    I hope someone finds this information useful. Took me a little to find this out….

    ——————————-

    One problem that persists and I havent found a solution on the web is:

    On Outlook-Email-Files (*.msg) the DoPreview-Method returns a HRESULT_EFAIL-error. How can I circumevent this or rather have a preview of Emailmessages like in Outlooks Preview Pane??

    Thnx

    dflag

  52. d kat says:

    Sadly all the links lead me to a page Error or to what looks like malware

    http://www.winhelponline.com/…/.html (caution!)

    I don't know why WIndows does not have an easy way to add extentions to the preview handler.  If it has a file association then windows should pick up on what app is used for opening and use that info for the preview handler.  

  53. Mizan Rahman says:

    Hi Stephen,  

    I need to host the preview handler on a C# Form.  For example, suppose I have a full path of a text file (.txt), I would like to preview the file within a GroupBox control on a .NET WinForm.  How can I do that?

    Thank you for this great article.

  54. Michael says:

    Just wanted to say thank you for this.  I've been trying to get flac files to play in explorer for ages and this was the key! 🙂

    Thanks again

  55. Marko says:

    Is there a way to preview files in simple windows form. It looks like Preview Handlers form the article are embedded and cannot be used in code, only in Windows?

    Thanks

  56. txg says:

    anyone know if this can be used to preview ebook files like .mobi or .epub?

  57. wha happa? says:

    Link went dead!!! >,<  anyone know where this can be found now for DL?

  58. DK says:

    Cool tool, why outlook no have built in?

  59. Stefan says:

    Great tool! 🙂

  60. Mike says:

    I have been trying to figure out how to preview .skp files (Google Sketchup).  Is there a preview handler builder available with a good gui?  

  61. dg says:

    thanks! this worked to fix Outlook 2013 issue. been looking for days on how to get the issue resolved. awesome little tool!

  62. Bill Gale says:

    Still using under Windows 7 Pro in 2014.  Works great!  

  63. Wayne Hammond says:

    This helped fix an issue I was having, great tool

  64. Burkhard Stiller says:

    Long time ago, Stephen, that you published this little gem, which is very useful even theses days – congratulations!

    I'm using it to add (at least) a textual preview for my diverse TXT-based files having their own special extensions…

    I want to share some errors I encountered, and how I solved them, with those who will download the PreviewHandlerEditor.zip after me and might run into comparable problems…

    I'm running VS 2010 (Vista). After loading the project it was converted flawlessly w/o errors and warnings – cool. Then, when building it, I got an Error#3 (telling me, that something was wrong with the VS RC.EXE -Path.

    > Solution: I modified the "Command line for pre-build events" entry on the project's property's BuildEvents-Tab to reflect the correct location of my resource compiler on my machine. Afterwards I was able to re-build the debug and release versions.

    Next, I ran into an error telling me that a SecurityException was thrown while reading a registry value. This was only happening within an enumeration loop (the loop where those entries were read from the registry defining existing preview handlers). The error said that I did not have enough rights reading the registry-key in question! But, I was running the whole thing in full Admin-mode!

    > Solution: Starting a debug-session showed that there was only one registry entry on my machine that was causing the exception: On my computer it was [HKEY_CLASSES_ROOTWindows.XPSReachViewer]. With the help of Vista's  regedt32.exe I was able to locate the item and found that some permissions were broken in the sub-keys "open" and "print". After taking over ownership of the whole Windows.XPSReachViewer registry node including all subkeys and re-adding administrative privileges again, all problems (run-time exceptions) were gone!

    > Bottom Line: If you run into problems starting the PreviewHandlerEditor.exe contained in the ZIP-File (freezing + showing up SecurityExceptions) then you might share the same "corrupted registry entry" – problem with me.

  65. jlockley says:

    It works for Windows 7 as well in fixing the PDF preview handler mess (all solutions are given for 64 bit. I seem to have 32) Interestingly it only shows Adobe PDF for Vista even after a reinstall. At least it's a pointer in the right direction. Thanks.

  66. YoshM says:

    The download links here don't seem to work anymore. However, I find a correct link:

    blogs.msdn.com/…/PreviewHandlerEditor.zip

    I found that link at:

    superuser.com/…/877927

  67. Chris van der Geugten, The Netherlands says:

    Unfortunately not all possible extensions are shown in the combobox Classes/extensions.

    for example the extension ".sample" ( used in git/hook

    It can also happen with extensions that are registered during installation of specific software.

    Could you adapt the GUI so that we can also associate directly to a "new" or self written extension , or that we can add extensions to the list of Classes/extensions. Thanks

  68. Ron Rice says:

    I have the same question as Newbie did, but do not see any replies for JPEG previewers.

    I converted from Outlook Express to Outlook 2007, and am amazed that my old OE has better previewers than the newer, bigger Outlook.

    Any help so I can see my Jpeg attachments again?

    Thanks,

    Ron

    newbie 2 Jan 2009 7:54 PM #

    I'm testing out this and the excellent handler framework, and I've come across an issue/question. I can't seem to get jpg/gif/bmp files to preview properly in the code i'm writing, though other file types (office, pdf, etc.) work fine as in the example code. Jpg/Gif/Bmp files preview just fine in the Vista explorer preview pane, so I don't think there's any issue in my registry, etc., but I can't find out what previewer is used for them (none shows in HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPreviewHandlers).

    Any thoughts or guidance on this would be much appreciated!