Long paths not working in windows 2019

Bhaskar Venkatesha 1 Reputation point
2022-02-10T11:16:42.123+00:00

Followed the steps given below to enable long paths and rebooted the machine

  1. Press Win + R keys on your keyboard and type regedit then press Enter. Registry Editor will be opened.
  2. Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
  3. Edit LongPathsEnabled and set it to 1.
  4. Press Win + R keys on your keyboard and type gpedit.msc then press Enter. Group Policy Editor will be opened.
  5. Go to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem, then enable the Enable Win32 long paths option.
    6.Restart machine.

Executed the below program to check if the file gets created in the already existing folder structure C:\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz


int main()
{
HANDLE h = CreateFileA(
"C:\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\abcdefghijklmnopqrstuvwxyz\012345678901234567890123456789.txt",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_TEMPORARY,
NULL);

if (h == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); printf("err %dn", err); getchar(); return 1; }
printf("Created\n");
getchar();

return 0;
}


The above program failed to create the file and produced the following output
err 3

The same program worked in windows 2016

What additional thing needs to be done in windows 2019 for long paths to work?

Machine details
Windows server 2019
Microsoft windows Server
Version 1809 (OS build 17763.316)

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,738 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 39,351 Reputation points
    2022-02-11T09:48:37.903+00:00

    Hi there,

    If this works on Windows 2016 it should work on Windows 2019 too. You might have configured them wrong or defined the long path differently. You can try the Powershell command and see if that helps you.

    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
    -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

    Also note the maximum path of 32,767 characters is approximate, because the "\?\" prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.

    Maximum Path Length Limitation
    https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell


    --If the reply is helpful, please Upvote and Accept it as an answer--


  2. Castorix31 81,636 Reputation points
    2022-02-11T13:05:39.557+00:00

    I tested on Windows 10 and I got the same error (3)
    But it worked by using :

      HANDLE h = CreateFileW(L"\\\\?\\C:\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\abcdefghijklmnopqrstuvwxyz\\012345678901234567890123456789.txt",
                
    

  3. EckiS 821 Reputation points
    2022-02-15T06:02:39.09+00:00

    from the documentation:
    "These are the file management functions that no longer have MAX_PATH restrictions if you opt-in to long path behavior: CopyFileW, CopyFile2, CopyFileExW, CreateFileW, CreateFile2, CreateHardLinkW, CreateSymbolicLinkW, DeleteFileW, FindFirstFileW, FindFirstFileExW, FindNextFileW, GetFileAttributesW, GetFileAttributesExW, SetFileAttributesW, GetFullPathNameW, GetLongPathNameW, MoveFileW, MoveFileExW, MoveFileWithProgressW, ReplaceFileW, SearchPathW, FindFirstFileNameW, FindNextFileNameW, FindFirstStreamW, FindNextStreamW, GetCompressedFileSizeW, GetFinalPathNameByHandleW."

    as you can see: CreateFileA is not in the list.
    in fact: not one of them is the ANSI version.
    so if CreateFileA ever worked for you (which I still somehow doubt. Perhaps you added the "\?\" prefix?) you relied on undocumented behavior.