Symbolic link creation requires usage of NTFS type file system partition and to have a permission from user security scope.
There are 3 behaviors based on computer configuration:
- Developer Mode: using a special flag to
CreateSymbolicLinkW
API - Privileged permission to allow creation of symbolic link
- Not allowed at all (unless in group Administrators). Default.
- Behavior 1 is “opt-in” per program.
- Behavior 2 is “always permitted” for any programs when user owns privilege.
- Behavior 3 is “never allowed” for any non-administrator user.
POSIX has unified symbolic link object. Symbolic link can target file, directories and any other file system objects. Target type is resolved at runtime. Usually by VFS (Virtual File System) layer in kernel, by enquiry of target file system object. POSIX does not mention VFS, but all UNIX© kernels have VFS.
NTFS, and hence Windows, have separated object for regular file and directory. API user shall declare object kind (file or directory) at creation time. Target type is resolved from symbolic link itself and inside NTFS layer. Contrary to POSIX, no proper VFS in Windows architecture is visible, even if a file system object cache exists since NT area.
A consequence on Windows is for many tools to require target existence to be able to create a symbolic link to this target. Even if Win32 API itself does not requires presence of target at creation time. Those tools can then decide if they create a file or directory symbolic link. And refuses to create symbolic link to other filesystem object types.
References:
- https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
- https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw
When user account has Developer Mode activated, add this flags when calling
CreateSymbolicLinkW
API:
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
API signature for CreateSymbolicLinkW
:
BOOLEAN CreateSymbolicLinkW(
[in] LPCWSTR lpSymlinkFileName,
[in] LPCWSTR lpTargetFileName,
[in] DWORD dwFlags
);
Program will then be able to create symbolic link as long as there are running with user security scope.
Named SeCreateSymbolicLinkPrivilege
.
Because of Developer Mode in Windows 10 and later, not having this permission do not prevent an user to allow programs to create symbolic link.
Only tentative of symbolic link creation allows discovery of permission.
This error happens in those two cases:
- No privilege / No Developer Mode
- No privilege / Developer Mode / No special flag
Windows Win32 error ERROR_PRIVILEGE_NOT_HELD
will be reported. For example:
Failed to create symbolic link.
Error(0x00000522): A required privilege is not held by the client.
Symbolic link creation should success in those cases for user account running program:
- “Developer Mode” for user, and program use special flag in Windows API
- Privileged permission
SeCreateSymbolicLinkPrivilege
Beware, this is should, computer policies or NTFS partition configuration may still prevent symbolic link creation.
Currently (2024-10-30), checking if symbolic creation is allowed requires to
call CreateSymbolicLinkW
API and checks error result.
NTFS partition can be configured to limit symbolic link creation.
"This setting can be used in conjunction a symlink filesystem setting that can
be manipulated with the command line utility to control the kinds of symlinks
that are allowed on the machine.
Type fsutil behavior set symlinkevaluation /?
at the command line to get more
information about fsutil and symbolic links."