11

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..

4
  • The only way i know how Windows is going to re-generate the short-name is to copy the directory and delete the original. Of course that is not going to work for the Program Files. It's not possible to adjust the scripts? Also, i hope the script is not thinking the Program Files-directory is always PROGRA~1 because if that's the case your script will run in some serious trouble eventually because the short-names are not always the same. You could also ask for help upgrading the scripts to the long-name (instead of the short-name) findfirst etc. (if at all possible).
    – Rik
    Nov 27, 2013 at 21:24
  • I am aware of the issues with short names and I would never write those scripts myself. I would always use the env vars for this (%programfiles%). Renaming does indeed not work. Maybe I can do this from offline? Could be a work-around.
    – pgampe
    Nov 28, 2013 at 13:20
  • did you try running the command as admin? Create 8.3 name for an existing directory
    – phuclv
    May 21, 2017 at 16:21
  • Sure. It did not work.
    – pgampe
    May 21, 2017 at 21:31

2 Answers 2

6

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.
3
  • Good idea to use a directory jump :)
    – pgampe
    Nov 29, 2013 at 14:28
  • Are changes made by mklink permanent or they just work in batch script which is being run? Sorry I don't have enough info about symlinks and junctions. Mar 29, 2018 at 9:58
  • @AlirezaMohamadi Changes made with mklink are permanent. Just like mkdir.
    – Rik
    Mar 29, 2018 at 13:57
10

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.

2
  • 2
    FWIW- I didn't need to reboot my computer for any of this. Also, you can selectively enable/disable 8.3 on different drives. The registry location for all these settings is HKLM:\System\CurrentControlSet\Control\FileSystem\Ntfs*. See support.microsoft.com/en-us/kb/121007
    – Coruscate5
    Dec 7, 2016 at 21:45
  • Yes, I just stayed where I was and did : Feb 15, 2017 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .