Changes in registry startup key between Windows XP and Windows 7

Several days ago I had an issue reported where one of my applications was causing a strange folder to open when the user logged in to their computer.  My application is supposed to auto-start when the user logs in to their computer, but it was never starting on these computers – only opening a strange folder.  After doing some testing, I discovered this was happening on Windows XP machines, but not Windows 7 (and presumably Windows Vista).  I did some research and discovered that Windows XP and Windows 7 interprets paths slightly differently from the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run registry key.

Here’s the scenario:

  1. I have a launcher app that acts as an auto-updater and it gets executed at Windows startup.  The path is:
    C:\Program Files\Smart Association\LifeMed Install\AutoUpdater.exe
  2. The auto-updater will compare MD5 hashes for all the files in C:\Program Files\Smart Association\LifeMed\*.* and if they’re different, it will automatically update them.
  3. Even though the HKLM Run entry was set to the exe in the “LifeMed Install” folder, on Windows XP the LifeMed folder would automatically open (instead of launching the AutoUpdater.exe).  This seemed really strange to me, since I never point to anything in that folder.

The problem was that I forgot to put double quotes around the path.  That made sense to me.  What didn’t make sense is why it was bringing up a folder I didn’t even reference in the path.  Apparently in Windows 7, the OS will attempt to interpret the entire path (even if there are no quotes), so the auto-startup works just fine.  In Windows XP, it’s a little more complicated.  Any time there is a space in the path, Windows will check to see if that path exists, and if it does, it will use that.  For example, the first space is between “Program” and “Files”, but since C:Program doesn’t exist, it goes to the next space in the path, which is between “Smart” and “Association”.  Since C:Program FilesSmart doesn’t exist, it goes to the next space, which is between “LifeMed” and “Install”.  C:Program FilesSmart AssociationLifeMed DOES exist, so this is the path that Windows XP tries to execute.

Ultimately the fix was just to simply add double quotes around the path – which of course I should have done from the beginning.  I just thought this behavior was a little odd, and in case any one else has experienced it, I thought an explanation might be helpful.

Leave a Reply