Reputation: 19
As a java software programmer, I'm used to create batch scripts for my software. In these scripts, I get the short name of the folders I work with, in order to make sure the software will work with command prompt (cmd). But then, one of my users on Windows 10 told me the software did not work on his computer. After some researches, I discovered that the algorithm that used to give me the folder short name did not work on his computer
I tried the same test code on various computers with different windows versions, and only on his computer I just could not get the expected short names.
Test code extracting the short name (sorry for the french text: it is for french users):
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
@ECHO -------------------------------------
@ECHO Version de Windows :
ver
@ECHO -------------------------------------
REM Test de nom court
SET ROOT_DIR=%~dp0
SET TMP_DIR=""
REM for "usebackq delims=" /d %%I in ("%ROOT_DIR%") do (
for /d %%I in ("%ROOT_DIR%") do (
if %TMP_DIR% == "" (
SET TMP_DIR=%%~sI
)
)
@ECHO test nom court du dossier courant: '%TMP_DIR%'
PAUSE
For example, with this folder (with deliberate long name) and given batch code:
D:\aa aaaaaa aa\vcxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\ccccccccccggggggggggggttttttttttttttttrrrrrrrrr dsdqkdhqk ;
-------------------------------------
Version de Windows :
Microsoft Windows [version 6.1.7601]
-------------------------------------
test nom court du dossier courant: 'D:\AAAAAA~1\VCXVVV~1\CCCCCC~1\'
Appuyez sur une touche pour continuer...
-------------------------------------
Version de Windows :
Microsoft Windows [version 10.0.17134.1040]
-------------------------------------
test nom court du dossier courant: 'D:\aa aaaaaa aa\vcxvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\ccccccccccggggggggggggttttttttttttttttrrrrrrrrr dsdqkdhqk ;'
Appuyez sur une touche pour continuer...
Due to this kind of answer, my batch scripts won't work because the command prompt will raise errors for too long lines.
Does anyone have any idea about how to get the expected short names on windows 10?
I don't know if it will help (I'm not a windows expert), but I did some research with regedit on his computer, and I found these:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem\NtfsAllowExtendedCharacter8dot3Rename = 0
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem\NtfsDisable8dot3NameCreation = 2
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet\Control\FileSystem\NtfsAllowExtendedCharacter8dot3Rename = 0
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation = 2
Thank you by advance for any solution to that problem.
Regards,
Upvotes: 1
Views: 2455
Reputation: 19
@Compo had the right answer: My user has windows 10 pro with a SSD. On windows 10 (at least pro), the default behaviour concerning SSD seems to be "do not allow short file names".
So, I put the "NtfsDisable8dot3NameCreation" registry value to 0 using this command with PowerShell run as administrator:
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\FileSystem\" -Name NtfsDisable8dot3NameCreation -Value 0
After rebooting the computer and installing my software to a new folder, it did work.
The only limitation of this is that it doesn't work in previously created folders: these folders were not created with short names, so there is no possibility to get their short name...
Upvotes: 1