Windows server path length

Maximum Path Length Limitation

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is «D:\some 256-character path string » where » » represents the invisible terminating null character for the current system codepage. (The characters are used here for visual clarity and cannot be part of a valid path string.)

For example, you may hit this limitation if you are cloning a git repo that has long file names into a folder that itself has a long name.

File I/O functions in the Windows API convert «/» to «\» as part of converting the name to an NT-style name, except when using the «\\?\» prefix as detailed in the following sections.

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the «\\?\» prefix. For example, «\\?\D:\very long path«.

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.

The «\\?\» prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the «\\?\UNC\» prefix. For example, «\\?\UNC\server\share», where «server» is the name of the computer and «share» is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the «\\?\» prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.

There is no need to perform any Unicode normalization on path and file name strings for use by the Windows file I/O API functions because the file system treats path and file names as an opaque sequence of WCHARs. Any normalization that your application requires should be performed with this in mind, external of any calls to related Windows file I/O API functions.

When using an API to create a directory, the specified path cannot be so long that you cannot append an 8.3 file name (that is, the directory name cannot exceed MAX_PATH minus 12).

The shell and the file system have different requirements. It is possible to create a path with the Windows API that the shell user interface is not able to interpret properly.

Читайте также:  Run debian on windows

Enable Long Paths in Windows 10, Version 1607, and Later

Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.

To enable the new long path behavior, both of the following conditions must be met:

  • The registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD) must exist and be set to 1. The key’s value will be cached by the system (per process) after the first call to an affected Win32 file or directory function (see below for the list of functions). The registry key will not be reloaded during the lifetime of the process. In order for all apps on the system to recognize the value of the key, a reboot might be required because some processes may have started before the key was set.

You can also copy this code to a .reg file which can set this for you:

This registry key can also be controlled via Group Policy at Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths .

The application manifest must also include the longPathAware element.

These are the directory management functions that no longer have MAX_PATH restrictions if you opt-in to long path behavior: CreateDirectoryW, CreateDirectoryExW GetCurrentDirectoryW RemoveDirectoryW SetCurrentDirectoryW.

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.

Enable NTFS long paths in Windows Server 2016 and 2019 by Group Policy

Windows Server 2016 was finally released last week, meaning we can finally lift the idiotic 260 characters limitation for NTFS paths. In this post I’ll show you how to configure the Enable Win32 long paths setting for the NTFS file system, through Group Policy (a GPO ). Also for Windows Server 2019.

Note: this still goes for Windows Server 2019 too!

Maximum Path Length Limitation (MAX_PATH) in Windows Server#

Microsoft writes about the Maximum Path Length Limitation on MSDN, and they write:

Maximum Path Length Limitation

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is “D:\some 256-character path string ” where “ ” represents the invisible terminating null character for the current system codepage. (The characters are used here for visual clarity and cannot be part of a valid path string.)

In the past, this 260 characters limitation caused errors and discomfort. Especially in the web hosting branche where you sometimes have to be able to save long file names. This resulted in (too) long paths and thus errors.

Fortunately, this limitation can now be unset and removed. Per default the limitation still exists though, so we need to set up a Local Group Policy. Or a Group Policy (GPO) in my case, since my server is in an Active Directory domain network.

You’ll learn how to set up a GPO to enable NTFS long paths in Windows Server 2016 and Windows Server 2019 using the LongPathsEnabled registry value.

Читайте также:  Установка openvpn для mac os

Note: enabling “Long Paths” doesn’t magically remove the 260 character limit, it enables longer paths in certain situations. Adam Fowler has a bit more information about this is. Or are you wondering how to increase the configured maxUrlLength value in Windows Server & IIS? This’ll fix an IIS error The length of the URL for this request exceeds the configured maxUrlLength value.

But first things first.

You need to be able to set up this GPO using administrative templates (.admx) for Windows Server 2016. Because, in my situation, my Active Directory server is Windows Server 2012 R2 and doesn’t provide GPO settings for 2016.

Download Administrative Templates (.admx) for Windows 10 and Windows Server 2016 and 2019#

If you are, as me, on Windows Server 2012 R2, you need administrative templates ( .admx files) for Windows Server 2016 to configure 2016 specific Group Policy Objects. Same goes for Server 2019.

These few steps help you setting them up in your environment.

Download and install administrative templates for Windows Server 2016 and 2019 in your Windows Server 2012 R2 Active Directory#

Folow these steps:

  1. Download Windows 10 and Windows Server 2016 specific administrative templates – or .admx files.
  2. Install the downloaded .msi file Windows 10 and Windows Server 2016 ADMX.msi on a supported system: Windows 10 , Windows 7, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2. You also need user rights to run the Group Policy Management Editor ( gpme.msc ), or the Group Policy Object Editor ( gpedit.msc ). But that’s for later use.
  3. The administrative templates are installed in C:\Program Files (x86)\Microsoft Group Policy\Windows 10 and Windows Server 2016 , or whatever directory you provided during the installation. Copy over the entire folder PolicyDefinitions to your Primary Domain Controller’s SYSVOL\domain\Policies directory.
  4. Verify you’ve copied the folder, and not just the files. The full path is: SYSVOL\domain\Policies\PolicyDefinitions . This is explained in Microsoft’s Technet article Managing Group Policy ADMX Files Step-by-Step Guide.

That’s it, you now have Group Policy Objects available for Windows Server 2016. Let’s enable Win32 long paths support now.

Configure Enable Win32 long paths Group Policy#

Protip: learn how to set up WMI filters for Group Policy.

Now that you have your Windows Server 2016 Group Policy Objects available, it’s time to setup a GPO to enable NTFS long path support. Create the GPO in your preferred location, but be sure to target it on Windows Server 2016 only.

Please note that the GPO is called Enable Win32 long paths, not NTFS.

Enabling Win32 long paths will allow manifested win32 applications and Windows Store applications to access paths beyond the normal 260 character limit per node on file systems that support it. Enabling this setting will cause the long paths to be accessible within the process.

Start your Group Policy Management console and click through to the location where you want to add the GPO. Create a new GPO: Create a GPO in this domain, and Link it here. , and provide your GPO with a relevant name.

In the Settings tab, right click and choose Edit…. Now under Computer Configuration in the Group Policy Management Editor, click through to Policies > Administrative Templates > System > Filesystem. Configure and enable the Setting Enable Win32 long paths.

This is all you have to do to create the Group Policy for long Win32 paths. All that is left is to run gpupdate in an elevated cmd.exe command prompt.

Читайте также:  Eclipse php linux install

Verify LongPathsEnabled registry value#

If needed, you can use the following cmd.exe or PowerShell commands to verify the LongPathsEnabled registry value is set correctly:

A reboot is not required, and don’t forget your Windows Server 2019 servers.

question

Enable support for a max path length

Hi I have Windows Server 2019 and I need to enable support for a max path length. (The Default is 260 length) I set the registry » LongPathsEnabled » to «1» at HKLM\SYSTEM\CurrentControlSet\ControlFileSystem and also enable long path support via Group Policy Computer Configuration > Administrative Templates > System > Filesystem. Enable the policy Enable NTFS long paths. but still, I get the error «the file names would be too long for the destination folder» when I try to create a subfolder longer than 260 length Thanks in Advanced

Just checking in to see if the information provided was helpful.

If the reply helped you, please remember to accept as answer.
If no, please reply and tell us the current situation in order to provide further help.

5 Answers

Are you using File Explorer when creating the subfolder? If so, try creating the folder using PowerShell. I had a similar issue and ended up scripting the process.
Hope that helps.

Hi,
Thank you For your quick replay
We are working with a Document management system that already has a few TB of files. so it is not an option for me to start to create those directories. and also all the process of saving the fileד is from the software

I’m just spitballing here but would it be possible to change the path(s) the system uses to paths that use symbolic links to technically shorten the path? something like mklink /d c:\link “C:\reallylongpath”

@ItzikDahan-4347
Hi,
You could configure the Enable Win32 long paths setting for the NTFS file system, through Group Policy.
You need to be able to set up this GPO using administrative templates (.admx) for Windows Server 2019.
Folow these steps(Also for Windows Server 2019.):
1. Download Windows 10 and Windows Server 2016 specific administrative templates – or .admx files.
2. Install the downloaded .msi file Windows 10 and Windows Server 2016 ADMX.msi on a supported system. You also need user rights to run the Group Policy Management Editor (gpme.msc), or the Group Policy Object Editor (gpedit.msc).
3. The administrative templates are installed in C:\Program Files (x86)\Microsoft Group Policy\Windows 10 and Windows Server 2016, or whatever directory you provided during the installation. Copy over the entire folder PolicyDefinitions to your Primary Domain Controller’s SYSVOL\domain\Policies directory.
4. Verify you’ve copied the folder, and not just the files. The full path is: SYSVOL\domain\Policies\PolicyDefinitions. This is explained in Microsoft’s Technet article Managing Group Policy ADMX Files Step-by-Step Guide.

Start your Group Policy Management console and click through to the location where you want to add the GPO. Create a new GPO: Create a GPO in this domain, and Link it here. and provide your GPO with a relevant name.
In the Settings tab, right click and choose Edit…. Now under Computer Configuration in the Group Policy Management Editor, click through to Policies > Administrative Templates > System > Filesystem. Configure and enable the Setting Enable Win32 long paths.

Then run gpupdate in an elevated cmd.exe command prompt.

Hope above information can help you.

============================================
If the Answer is helpful, please click «Accept Answer» and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Оцените статью