How to force short name (8dot3) generation?

I have a problem with windows windows shortnames. Sometimes the short names do not seem to be generated for "Program Files" and "Program Files (x86)".

I verified that short name generation is enabled with fsutil behavior query disable8dot3 C: which tells me that the system wide setting is 2 (per volume) and the local value is 0 (create 8dot3 names).

It should look roughly like this (note that is is a german 32bit copy):

C:\>dir /a /x

 Verzeichnis von C:\

21.12.2011  00:17    <DIR>                       $Recycle.Bin
14.07.2009  05:53    <VERBINDUNG>   DOCUME~1     Documents and Settings [C:\Users]
09.01.2011  15:35    <VERBINDUNG>   DOKUME~1     Dokumente und Einstellungen [C:Users]
27.11.2013  15:11     2.147.016.704              pagefile.sys
14.07.2009  03:37    <DIR>                       PerfLogs
26.11.2013  17:31    <DIR>          PROGRA~1     Program Files
08.11.2013  21:58    <DIR>          PROGRA~2     ProgramData
09.01.2011  15:35    <VERBINDUNG>   PROGRA~3     Programme [C:\Program Files]
09.01.2011  15:35    <DIR>                       Recovery
26.11.2013  17:40    <DIR>          SYSTEM~1     System Volume Information
23.01.2011  15:00    <DIR>                       Temp
11.01.2011  20:56    <DIR>                       Users
08.11.2013  14:53    <DIR>                       Windows

However on another machine (64bit copy), this looks like C:>dir /a /x

 Verzeichnis von C:\

21.12.2011  00:17    <DIR>                       $Recycle.Bin
14.07.2009  05:53    <VERBINDUNG>   DOCUME~1     Documents and Settings [C:\Users]
09.01.2011  15:35    <VERBINDUNG>   DOKUME~1     Dokumente und Einstellungen [C:Users]
27.11.2013  15:11     2.147.016.704              pagefile.sys
14.07.2009  03:37    <DIR>                       PerfLogs
26.11.2013  17:31    <DIR>                       Program Files
26.11.2013  17:31    <DIR>                       Program Files (x86)
08.11.2013  21:58    <DIR>                       ProgramData
09.01.2011  15:35    <DIR>                       Recovery
26.11.2013  17:40    <DIR>          SYSTEM~1     System Volume Information
23.01.2011  15:00    <DIR>                       Temp
11.01.2011  20:56    <DIR>                       Users
08.11.2013  14:53    <DIR>                       Windows

As you might have noticed, the short names are missing for the program folders.

The question is now how to generate them, because I need those short names for a few older scripts. I tried with fsutil file setshortname "Program Files" "PROGRA~1", but this just gives me Access denied..


Like i said in my comment... The only way i know how Windows is going to re-generate the short-name is to copy the directory and delete the original. (not doable for the "Program Files" directory.)

It would be best to change the script to use long file- and folder-names. If the script uses PROGRA~1 it will get in trouble with installations where the drive was cloned in a way the directories where copied back. For example if ProgramData is copied first onto the disk it will be named PROGRA~1 and Program Files will be named PROGRA~2.

There is an option to keep the scripts working for now:

You could create a directory-junction from PROGRA~1 to C:\Program Files. That way the scripts keep working and you have time to change them.

mklink /J "C:\PROGRA~1" "C:\Program Files"

Output of mklink /?:

Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

To define shortnames (8dot3) for Program files do the following:

  1. Restart computer
  2. upon boot start in safemode with cmd prompt (F8 on my computer)
  3. Log in
  4. from cmd prompt enter the following cmds

    fsutil 8dot3name query
    fsutil behavior set disable8dot3 0
    fsutil file setshortname "Program Files" PROGRA~1
    dir /X
    

You should now see the shortname defined for program files. If you'd like, set the 8dot3name behavior back to the original setting which was returned by the query cmd.