Disabling Office 2003 Browser Inline Behavior
There’s a unique problem in an Office 2003 environment that may be encountered by add-in developers. Namely, by default, Office 2003 documents, when opened from a URL (for example, clicking on a link in an email or typing a URL into a browser address bar) will cause the document to open “inline” with the browser.
The problem with this, for add-in developers, is that while the WINWORD.EXE process is indeed launched, the add-in is not loaded (I’m still not sure why, but I’m guessing it’s due to the different security restrictions of being “hosted” in Internet Explorer). Aside from this, it’s generally problematic because the default menu bars and toolbars are not displayed by default…not the ideal behavior.
As it turns out, in Office 2007, the behavior is entirely different: the document always open in a standalone WINWORD.EXE process. So how can we get Office 2003 to behave the same way? A series of articles lead the way to an answer:
First, Microsoft actually has a KB (927009) which advises how to enabled Office 2003 behavior in an Office 2007 environment. This is the first clue that the core of the issue is a series of registry keys. Knowing which keys to look for, I simply checked the keys in an Office 2007 environment to get the values which would cause an application like Word to launch in standalone mode instead of inline mode (decimal 44 in the case of Word).
The next step was figuring out how to adjust these values in existing deployments. One option would have been to use a similar registry script as porposed in the KB but I decided to use a programmatic approach instead. I came across some hints on how to approach this task from a forum posting and MSDN articles.
The outcome was this script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
<span style="font-family: Lucida Console;"><span style="color: #008000;">/*=============================================================================</span> <span style="color: #008000;"> This file contains the scripts which are executed after installation of the </span> <span style="color: #008000;"> Office 2003 client update registry keys which would otherwise force Office </span> <span style="color: #008000;"> documents to open in Internet Explorer (inline behavior)</span> <span style="color: #008000;">=============================================================================*/</span> <span style="color: #008000;">// Key paths</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">commonRootPath = </span><span style="color: #a56dbc;">"HKLM\\SOFTWARE\\Classes\\"</span><span style="color: #000000;">;</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">commonPath = </span><span style="color: #a56dbc;">"SOFTWARE\\Classes\\"</span><span style="color: #000000;">;</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">commonKey = </span><span style="color: #a56dbc;">"BrowserFlags"</span><span style="color: #000000;">;</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">HKLM = </span><span style="color: #ff00ff;">0x80000002</span><span style="color: #000000;">;</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">// Instantiate the shell.</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">shell = WScript.CreateObject(</span><span style="color: #a56dbc;">"WScript.Shell"</span><span style="color: #000000;">);</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">// Holds the values for the key types</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">keyTypes = {</span> <span style="color: #ff0000;">String</span><span style="color: #000000;">:</span><span style="color: #a56dbc;">"REG_SZ"</span><span style="color: #000000;">, </span> <span style="color: #000000;">Number:</span><span style="color: #a56dbc;">"REG_DWORD"</span><span style="color: #000000;">, </span> <span style="color: #000000;">Binary:</span><span style="color: #a56dbc;">"REG_BINARY"</span><span style="color: #000000;">, </span> <span style="color: #000000;">ExpandableString:</span><span style="color: #a56dbc;">"REG_EXPAND_SZ"</span> <span style="color: #000000;">};</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">// Holds the array of all key paths (not including the shared "BrowserFlags" </span> <span style="color: #008000;">// DWORD key name) and the value to assign to the key (different for each</span> <span style="color: #008000;">// runtime).</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">keys = [</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.Document"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">},</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.Document.6"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">},</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.Document.8"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">},</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.Document.12"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">},</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.RTF.8"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">},</span> <span style="color: #000000;">{Class:</span><span style="color: #a56dbc;">"Word.DocumentMacroEnabled.12"</span><span style="color: #000000;">, Value:</span><span style="color: #ff00ff;">44</span><span style="color: #000000;">}</span> <span style="color: #000000;">];</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">/*-----------------------------------------------------------------------------</span> <span style="color: #008000;"> Main method.</span> <span style="color: #008000;">-----------------------------------------------------------------------------*/ </span> <span style="color: #4d70ea;">function </span><span style="color: #000000;">Run() {</span> <span style="color: #4d70ea;">try </span><span style="color: #000000;">{</span> <span style="color: #4d70ea;">for</span><span style="color: #000000;">(</span><span style="color: #4d70ea;">var </span><span style="color: #000000;">i = </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">; i < keys.length; i++) { </span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">key = keys[i];</span></span> <span style="font-family: Lucida Console;"> <span style="color: #4d70ea;">if</span><span style="color: #000000;">(RegistryKeyExists(key.Class)) { </span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">keyPath = commonRootPath + key.Class + </span><span style="color: #a56dbc;">"\\" </span><span style="color: #000000;">+ commonKey; </span></span> <span style="font-family: Lucida Console;"> <span style="color: #000000;">shell.RegWrite(keyPath, key.Value, keyTypes.Number);</span> <span style="color: #000000;">}</span> <span style="color: #000000;">} </span></span> <span style="font-family: Lucida Console;"> <span style="color: #000000;">shell.Popup(</span><span style="color: #a56dbc;">"Updated registry keys."</span><span style="color: #000000;">, </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">, </span><span style="color: #a56dbc;">"Completed"</span><span style="color: #000000;">, </span><span style="color: #ff00ff;">0 </span><span style="color: #000000;">+ </span><span style="color: #ff00ff;">64</span><span style="color: #000000;">);</span> <span style="color: #000000;">}</span> <span style="color: #4d70ea;">catch</span><span style="color: #000000;">(all) {</span> <span style="color: #008000;">// Failures are considered non-fatal.</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">errorMessage = </span><span style="color: #a56dbc;">"A non-fatal error occurred while configuring Word 2003\r\n"</span><span style="color: #000000;">;</span> <span style="color: #000000;">errorMessage += </span><span style="color: #a56dbc;">"document handling in IE.\r\n\r\n"</span><span style="color: #000000;">;</span> <span style="color: #000000;">errorMessage += </span><span style="color: #a56dbc;">"You can re-run this script at a later time from:\r\n\r\n"</span><span style="color: #000000;">;</span> <span style="color: #000000;">errorMessage += </span><span style="color: #a56dbc;">"[Program Files]\\[Common Files]\\FirstPoint\";</span> <span style="color: #000000;">errorMessage += </span><span style="color: #a56dbc;">"UpdateOffice2003RegistrySettings.js\r\n\r\n"</span><span style="color: #000000;">;</span> <span style="color: #000000;">errorMessage += </span><span style="color: #a56dbc;">"Press OK to continue."</span><span style="color: #000000;">;</span></span> <span style="font-family: Lucida Console;"> <span style="color: #000000;">shell.Popup(errorMessage, </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">, </span><span style="color: #a56dbc;">"Error"</span><span style="color: #000000;">, </span><span style="color: #ff00ff;">0 </span><span style="color: #000000;">+ </span><span style="color: #ff00ff;">48</span><span style="color: #000000;">);</span> <span style="color: #000000;">}</span> <span style="color: #000000;">}</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">/*-----------------------------------------------------------------------------</span> <span style="color: #008000;"> Checks to see if a registry key exists.</span> <span style="color: #008000;">-----------------------------------------------------------------------------*/</span> <span style="color: #4d70ea;">function </span><span style="color: #000000;">RegistryKeyExists(className) {</span> <span style="color: #4d70ea;">var </span><span style="color: #000000;">registry = GetObject(</span><span style="color: #a56dbc;">"winmgmts:\\\\.\\root\\default:StdRegProv"</span><span style="color: #000000;">); </span></span> <span style="font-family: Lucida Console;"> <span style="color: #4d70ea;">var </span><span style="color: #000000;">path = commonPath + className; </span></span> <span style="font-family: Lucida Console;"> <span style="color: #4d70ea;">var </span><span style="color: #000000;">value = registry.GetStringValue(HKLM, path, </span><span style="color: #a56dbc;">""</span><span style="color: #000000;">);</span></span> <span style="font-family: Lucida Console;"> <span style="color: #4d70ea;">return </span><span style="color: #000000;">value == </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">;</span> <span style="color: #000000;">}</span></span> <span style="font-family: Lucida Console;"><span style="color: #008000;">/*-----------------------------------------------------------------------------</span> <span style="color: #008000;"> Abstracts Popup()</span> <span style="color: #008000;">-----------------------------------------------------------------------------*/</span> <span style="color: #4d70ea;">function </span><span style="color: #000000;">Alert(string) {</span> <span style="color: #000000;">shell.Popup(string, </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">, </span><span style="color: #a56dbc;">"Message"</span><span style="color: #000000;">, </span><span style="color: #ff00ff;">0</span><span style="color: #000000;">);</span> <span style="color: #000000;">}</span></span> <span style="font-family: Lucida Console;"><span style="color: #000000;">Run();</span></span> |
Perhaps the most useful little tidbit in all of this is the RegistryKeyExists method which checks to see a registry path exists. A return value of 0 from any of the Get[KeyType]Value() method calls indicates that the path was found; it’s a very neat little trick to have up your sleeve.