26
04/12
Opening Mail Attachment Warning – How to Suppress Programmatically
Perhaps you’ve seen this dialog when using Microsoft Outlook:

You may have noticed that occasionally the “[a]lways ask before opening this type of file” is greyed out—as it is in the screenshot above. There’s actually some very interesting Windows heritage to this.
For backwards compatibility (the hallmark of all things weird and interesting in MS Windows) there’s a redundant registry hive in Windows—HKEY_CLASSES_ROOT, otherwise known as HKCR—which presents a “merged” view of HKLM\Software\Classes and HKCU\Software\Classes. The reason it exists “[f]or backwards compatibility” is that back in the day, when Windows was 16-bit, it wasn’t multi-user—there was no HKCU, since the distinction of multiple users didn’t exist, so it didn’t make sense to have a “current” one, and accordingly HHLM\Software\Classes and HKCU\Software\Classes were one hive—HKCR.
Under HKCR is Windows’ file association data. There’s a key under it for each file extension—all the keys which begin with a dot—and a plethora of keys with descriptive names.
The information about file types is split out into two keys—the key which represents its file extension, and the key which represents its actual logical type.
The key which represents a file extension has as its default value a REG_SZ which points to the actual logical type of that file extension, and accordingly another key under HKCR.
For example, if you have Chrome installed and setup as your default browser, you should be able to obtain the following from the command prompt:
C:\Users\rleahy>REG QUERY HKCR\.htm /ve
HKEY_CLASSES_ROOT\.htm
(Default) REG_SZ ChromeHTML
C:\Users\rleahy>REG QUERY HKCR\.html /ve
HKEY_CLASSES_ROOT\.html
(Default) REG_SZ ChromeHTML
.htm and .html are two separate file extensions—there are two separate keys for them under HKCR—but both of them have a pointer to the same logical file type—”ChromeHTML“.
UAC means that even if you’re logged in as an administrator, your programs are still running with user-only privileges. This means that even though all this file association data appears to be in the same hive, it’s not. Accordingly, Outlook may have the rights to modify some—if they’re defined in HKCU\Software\Classes—and may not have rights to modify others—if they’re defined in HKLM\Software\Classes. This is why the checkbox is always greyed out, and why tutorials elsewhere on the internet tell you to run Outlook as administrator to put these dialogs to rest.
But, editing the registry is a much simpler, much more straightforward, and much more scalable way to change this behaviour.
Under the key which represents the actual logical type of a file—in our example ChromeHTML—there either exists, or may exist, a value called “EditFlags“. It should be of the type REG_BINARY. Setting it to 00 00 01 00 will suppress the behaviour, whereas setting it to 00 00 00 00 will reenable the dialogs.
For our ChromeHTML example:
C:\Windows\system32>REG ADD HKCR\ChromeHTML /v EditFlags /f /t REG_BINARY /d 000 00100 The operation completed successfully.



















