NTFS 8.3 short names – solving the issues

In Part 1 I explained the fundamentals of NTFS 8.3 short names and the typical sorts of problems that they can cause which are mostly when short name creation has been disabled or when a short name is not preserved when a file is copied and the new copy is referred to by its original short name.

Ok, so how do short names get disabled? This TechNet article covers the values for the registry value “NtfsDisable8dot3NameCreation” which controls the short name behaviour. In the days of old, as in Windows XP and 2000, this value was by default 0, meaning that short name creation was not disabled so it was enabled (which is the default for new installations, to this day, when original Microsoft installation media is used). In those days, the only other legal registry value was 1 which meant that short name creation was disabled on all local volumes, which needed a reboot to take affect. In later operating systems, further values have been introduced to make the settings per volume (2) or to all volumes except the system drive (3) and, since Vista, a reboot is not required to affect a change.

Disabling of short names has become quite common place since Microsoft recommend to do so in a security guide found here. There’s also some evidence that file operations in folders containing large numbers of similarly named files can be slowed down dramatically by short name creations as the OS has to figure out unique names for each newly created file/folder.

In addition, the “format” command takes an optional /S: argument to either enable or disable short names and the default is now to disable so any Windows OS installed to a manually formatted partition, e.g. via ADK/AIK, will have short names disabled. I have seen this with systems created via SCCM 2012 which then causes problems with software that uses appinit_dlls.

To check if short names are disabled on a given volume, run the following as an administrator in a cmd prompt:

fsutil 8dot3name query c:

which will return something like the following if short name creation is disabled:

The volume state is: 1 (8dot3 name creation is disabled).
The registry state is: 2 (Per volume setting - the default).
Based on the above two settings, 8dot3 name creation is disabled on c:

You could of course also create a new file with a space in the name (remembering to use quotes around the file name) and then run “dir /x” against it to see if a short name is created or not. This approach has the advantage that it does not require administrative privilege.

Enabling it is then just a case of running the following:

fsutil 8dot3name set c: 0

however, any file or folder created when short name creation was disabled will still have no short name since they are only created at initial file/folder creation, not on subsequent accesses to the file even if short name creation has subsequently been enabled.

All is not lost as we can add short names for items that are missing them using  the fsutil command again, for example:

fsutil file setshortname "c:\program files" PROGRA~1
fsutil file setshortname "c:\program files (x86)" PROGRA~2

This approach can also be used to “repair” short names when they are incorrect, such as my robocopy example in Part 1. Note that if you are switching around two short names for two files/folders, such as in the above example, then you will need to use a temporary short name for one of them since short names must be unique per folder at all times:

switchin short names

Notice in the above that the temporary short name I used was “SHORTY” which doesn’t include the “~” character since short names don’t actually require it, it’s just that the Microsoft algorithm used to generate short names uses it. You could in theory therefore run with the short name as “SHORTY” but only if there are no existing references to the expected short name, “PROGRA~1” in the above example, such as in the registry.

The above works fine for small numbers of files/folders, such as items that need to work in the good old appinit_dlls registry value but for large scale fixing of missing or incorrect short names then it would just be a little bit tedious to do this manually. Therefore I have written a utility that will copy the short names from existing files/folders and apply them to a copy of these files/folders in a new location. The idea is that you have used robocopy or similar to (selectively) copy files to a new location but as covered in Part 1, this will likely wreck the short names so that programs, like Office, may no longer work.

So if we have recursively copied say “c:\program files (x86)” to d:\ then run the following to apply the same short names from c: to d:

CloneShortNames.exe -s "\\?\c:\Program Files (x86)" -d \\?\d:\

Notice the use of the “\\?\” sequence to disable path parsing, as described here, to enable long file names to be used, up to 32K characters, rather than hitting the usual MAX_PATH (260) character limit. It’s optional but a good idea, where utilities support it.

You can also specify a -v to get verbose output of what is going on and -c to continue should any errors occur. It should be run as an administrative user.

It is available here, is used entirely at your own risk since it is completely unwarranted, and requires the Visual C++ 2013 redistributables which are available here.

 

Author: guyrleech

I wrote my first program, in BASIC, in 1980, was a Unix developer after graduation from Manchester University (Computer Science) and then became a consultant, initially with Citrix WinFrame, in 1995 and later into Terminal Server/Services and thence EUC. I currently hold the Citrix CTP, Microsoft MVP, VMware vExpert and Parallels VIPP awards. I invented and wrote the first few versions of the security product which is now Ivanti Application Control (formerly AppSense Application Manager). I now work as an freelance consultant-cum-developer, live in West Yorkshire, England; have a wife, three children, one grandchild and two dogs and was a keen competitive runner until health problems put an end to that fun.

16 thoughts on “NTFS 8.3 short names – solving the issues”

  1. Thank you for this application Guy, I’ve had to use this a few times recently and have found it incredibly useful.

    One question, do you have a list of error codes? As with all DOS based stuff, the syntax is very particular and I have experienced Error 2’s, Error 3’s and 161 errors.

    It would be nice to have a quick reference to was an error 3 was, rather than try and work out I had an extra backslash in the path that shouldn’t have been!

    1. Thanks for the positive feedback. All error codes are standard windows ones so just run “net helpmsg " in a cmd prompt to get the error text. 2 is "The system cannot find the file specified", 3 is "The system cannot find the path specified" and 161 is "The specified path is invalid"

  2. When i us the command fsutil file setshortname “c:\program files” PROGRA~1
    I get the error Access Denied. Any ideas (I’m running in sommand prompt as an administrator

    1. I suspect that it may be because the folder is owned by the “TrustedInstaller” account, a mechanism brought in with Vista to reduce the attack surface by protecting the OS from administrators by not giving them write permissions to key folders and files. I’d try taking ownership of the folder and trying again, remembering to set it back correctly afterwards.

      1. my d:\program files was owned by System. changing it to me did not change the “access denied” when attempting to add the shortname.

  3. Hello Guy, this blog is very interesting and I’d really like to get hold of a copy of “CloneShortNames.exe” to help me work on a problem with recursively generating 8.3 file names but unfortunately the link above is broken, are you able to assist?

  4. Hi Guy,
    What functions did you use to access the location property of the file in order to get the shortname?
    I want to write a similar utility in Free Pascal. Any chance you could share the source code?

  5. What do I do if I have a directory D:\Program Files and want to make everything short names underneath it?

    1. I tried copying files from my d:\program files\myapp to c:\program files\myapp. During execution in a admin cmd prompt:

      F:\Program Files>CloneShortNames.exe -v -s “\\?\c:\Program Files\myapp” -d \\?\f:
      Failed to open file “\\?\f:\Program Files\myapp\data\.lic\lic00000001.lic” f
      or writing – error 5
      Set “\\?\f:\Program Files\myapp\data\.lic\lic00000001.lic” to “LIC000~1.LIC”

      Changed 0 of 3 entries found with 1 errors

      1. I tried another specific directory and it worked, but there are about 50% that don’t have the short name now.

        F:\Program Files>CloneShortNames.exe -v -s “\\?\c:\Program Files\myapp\data\server.dll” -d \\?\f:
        Failed FindFirstFile on “\\?\c:\Program Files\myapp\data\server.dll” – error 267
        Changed 0 of 0 entries found with 1 errors

        F:\Program Files>net helpmsg 267

        The directory name is invalid.

      2. For some reason it doesn’t like the directory name – not sure why though sorry

      3. Error 5 is access denied so check permissions and ensure that you really are running as an admin

  6. Hello, Any chance you can update the link for CloneShortNames.exe again? The current Dropbox one no longer appears active.

Leave a reply to guyrleech Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.