Using NT registry calls to solve CR-LF issue with text files.

John E. Malmberg wb8tyw at
Wed Feb 9 05:57:10 GMT 2000

Gunnar Degnbol <degnbol at> wrote:

> At 08:20 07-02-2000 +1100, John E. Malmberg wrote:
> >Beau Kuiper <ekuiperba at> wrote:
> > >
> > > On Sun, 6 Feb 2000, John E. Malmberg wrote:
> >
> >Windows actually uses two methods of determining a file type.  The first
> >a registry, and the second is to examine the first two bytes of the file
> >a signature.  Some programs use the signature over the file type.
> I have looked at how Windows determines MIME types. The url is
> It can be done using FindMimeFromData(), but it won't work.  If the MIME
> type can't be determined more precisely than 'text/plain' (after
> considering the type reported by a web server, magic bytes, whether the
> data looks like a binary or text, and the extension), and the file is
> associated with an application, the type is set to
> 'application/octet-stream'.  So, for example, a .C file will not be
> reported as a text file if you have a C++ compiler.  Nothing in the
> registry indicates that it is a text file.
> The reasoning behind this behaviour is amazing:
> "As an example, this is necessary when downloading, among others, .bat and
> cmd files, which are plain text files, are frequently identified by the
> server as 'text/plain', and have no associated MIME type in the registry.
> Without the final check for an associated application, these would be
> displayed in-pane, whereas the desired behavior is to launch the command
> interpreter."
> The Internet is just like your hard disk, or your LAN, so when you click
> a .BAT file in your integrated file manager/browser you will obviously
> to run it before reading it.
> I guess this has been fixed many times over (once for each dangerous file
> type).

I was only looking at using the extension to MIME table in the registry, not
the tests for figuring out how to do nasty things to the users.

Assuming that a what a www server reports as a "text/plain" or other MIME
type should be checked for special interpretation is a bug.  It causes
problems when using a Microsoft browser to view web sites that are not run
by Microsoft WEB Servers.  There is no reason to implement that feature.

That particular feature is also present in some Windows Programs.  A bug
tracking software package that we use implements it.  The person making the
entry attached a .BAT file associated with the fix.  Instead of displaying
the contents as one would expect, opening it caused it to be executed.
Users need to remember to rename those files to .TXT before attaching them.

For my purposes, just the "text/*" and "application/postscript" of the Known
MIME types would need to be handled as text files, all others as binary
files.  Again, provided that the option was set for that share.

Interestingly, Notepad seems to be the only editor/viewer I have seen that
has problems with UNIX text files.  Dos EDIT can handle them, so can Write
and WordPad, Even the Quickview applet can figure them out.

wb8tyw at

More information about the samba-technical mailing list