Thursday 15 December 2011

How to open office files inside current window

I had a bug today when a program i was working on didn't work, after fixing the file associations, it worked for windows xp, but one of my clients need it to work for windows 7, however in windows 7 there is no real file association menu.
This fix will help you mostly if you are trying to open office files in the same browser window, and:
a) it opens in new office document.
b) it prompt is not displayed(it might be displayed after a few alt+tab)

This will fix it, there will be no prompt of "what do you want to do with", or "do you want to save or open this file", nor will it attempt to open it in a word window, instead it will open in the browser / WebBrowser window.

The fix is simple, make a text file, copy the next content, rename to something.reg, and run. you can incorporate it into the installer of you program to make sure the clients run it.
content:


Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document.8]
"BrowserFlags"=dword:80000024

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.RTF.8]
"BrowserFlags"=dword:80000024

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document.12]
"BrowserFlags"=dword:80000024

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.DocumentMacroEnabled.12]
"BrowserFlags"=dword:80000024

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.8]
"BrowserFlags"=dword:80000A00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.12]
"BrowserFlags"=dword:80000A00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.SheetMacroEnabled.12]
"BrowserFlags"=dword:80000A00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.SheetBinaryMacroEnabled.12]
"BrowserFlags"=dword:80000A00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.Show.8]
"BrowserFlags"=dword:800000A0

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.Show.12]
"BrowserFlags"=dword:800000A0

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.ShowMacroEnabled.12]
"BrowserFlags"=dword:800000A0

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShow.8]
"BrowserFlags"=dword:800000A0

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShow.12]
"BrowserFlags"=dword:800000A0

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\PowerPoint.SlideShowMacroEnabled.12]
"BrowserFlags"=dword:800000A0


[HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\AttachmentExecute\{0002DF01-0000-0000-C000-000000000046}]
"Word.Document.8" =dword:0
"Word.RTF.8" =dword:0
"Word.DocumentMacroEnabled.12"=dword:0
"Word.Document.12"=dword:0
"Word.DocumentMacroEnabled.12"=dword:0
"Excel.Sheet.8"=dword:0
"Excel.Sheet.12"=dword:0
"Excel.SheetMacroEnabled.12"=dword:0
"Excel.SheetBinaryMacroEnabled.12"=dword:0
"PowerPoint.Show.8"=dword:0
"PowerPoint.Show.12"=dword:0
"PowerPoint.ShowMacroEnabled.12"=dword:0
"PowerPoint.SlideShow.8"=dword:0
"PowerPoint.SlideShow.12"=dword:0
"PowerPoint.SlideShowMacroEnabled.12"=dword:0




Of course you can expand this for other files types, just add the names they are defined under in the registry.
If you are wondering, the first half ( up to [HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\AttachmentExecute\{0002DF01-0000-0000-C000-000000000046}]) is about the new window, the other is fixing the prompt.

The following KB resources were used:
http://support.microsoft.com/kb/927009
http://www.winhelponline.com/blog/reset-the-always-ask-before-opening-this-type-of-file-setting/