Lately I’ve spent a lot of time developing batch files for Edu2, writing for weirdness for batch renames and having fun with the command-line in general, since it is my tool of choice that goes beyond simple Explorer and SVN Tortoise jobs. And because of that I’ve found a few quirks and bugs that are either funny or at least worth noting since they are a PITA to track down.

How to crash cmd.exe

Plain and simple:

for /R %f in () do echo

crashes cmd.exe in Vista

Environment Variable Mess-Up

Maybe you know the environment settings dialog in XP/Vista. It allows you to specify environment variables both for the global environment and for the current user. (The former only if you’re an admin though.) A neat feature is that you can, of course, set the same environment variable twice and Vista/XP will merge them to one, which naturally allows for some neat system configuration.

However, it has its issues, too, of course.. Notably it handles case-sensitivity of environment variable names inconsistently, which results in some pretty weird behavior.

For example let’s assume we have a global and a user PATH environment variable, then Windows would merge the two, so that for applications PATH will be %PATH_global% %PATH_user% (where _global and _user refer to specific variables). You can easily try that by opening cmd.exe and typing in set path and notice how they are merged.

Now what happens if you have e.g. a global Path and a local PATH. You’d expect that they either show up as two different environment variables (if Windows treats them as case-sensitive) or they will be merged into one variable again (if they are treated case-insensitively). Sadly none of the above happens: $ set path will return Path = %Path_global% %Path_global%, which is both useless and can cause severe headaches, when only one half of your environment variable is available suddenly (for example after installing a program that changes or adds environment variables).

What happens? My guess and the only possible explanation are that Vista’s (maybe XP’s, too) handling is inconsistent. Detection of variables that need to be merged is case-insensitive, while the actual merging is not. It fails to find the user environment variable and instead uses the global one again (maybe it uses the same buffer to cache their value before concatenating them).

It took me some time to figure it out because, obviously, the set command and everything else treats them as case-insensitive.

File Associations

I’ve been using Notepad++ for over half a year now and I really really like it. But a few days ago I made the mistake of switching over to using it exclusively over notepad and for that I decided to change its file associations. Thank god it provides a simple dialog for that in its preferences window and it was a nice and easy task. Except that I also changed the file associations for .bat and .cmd files and instead of changing the “Edit” verb it changed the “Open/Execute” verb, which caused .bat files to only be opened in Notepad++ instead of being executed.

Windows 95/98/ME/2000/XP had a really nice file association tab in their folder options which gave you total control over pretty much all aspects (except for some obscure cases where you had no choice but use regedit to change things). Now Vista’s designer apparently have decided that it gives users too much control and that that is a bad idea - so they have totally crippled it. I repeat: totally and fully crippled it. Instead of being able to edit and manage various verbs, specify DDE actions, setting a default verb, etc. etc., you only have a “Change Action” button that only allows you to specify the command-line. They have also moved it to System Settings, which is probably a better location than Folder Options where it was next to the visual appearance tab, but it’s totally useless now - as are more freeware tools that you find on the internet :(. After some cursing, goggling and worrying I eventually found some .reg files that restore Vista’s default associations but that’s really not what I would call a perfect solution.

Stay tuned for a last blog post about Edu2: a post-mortem (coming soon hopefully) and more,
Andreas