Create and inspect Win32 file and folder reparse points such as hard links, junctions and symbolic links.
Issues and discussion are welcome, and code is by invitation while the design settles, as CONTRIBUTING.md says.
This library provides an API to create and inspect Win32 file and folder reparse points such as hard links, junctions (also known as soft links) and symbolic links. It wraps the Win32 APIs through P/Invoke, so it runs only on Windows, and targets .NET Framework 4.5.1. The repository also holds NCode_cReparsePoints, a PowerShell DSC resource built on the library, which isn't part of the package.
Add the package to a project:
dotnet add package NCode.ReparsePointsusing System;
using NCode.ReparsePoints;
internal static class Program
{
private static void Main()
{
var provider = ReparsePointFactory.Provider;
provider.CreateLink(@"D:\NewJunction", @"C:\SourceDir", LinkType.Junction);
var link = provider.GetLink(@"D:\NewJunction");
Console.WriteLine("Type: {0}", link.Type);
Console.WriteLine("Target: {0}", link.Target);
}
}ReparsePointFactory.Provider returns the default IReparsePointProvider, and ReparsePointFactory.Create() a new one:
| Member | What it does |
|---|---|
LinkType GetLinkType(string path) |
Says whether the path is a hard link, a junction, a symbolic link or none of them (LinkType.Unknown). |
ReparseLink GetLink(string path) |
Returns the link's Attributes (FileAttributes), Type (LinkType) and Target; the target of a hard link can't be determined, so it is null. |
void CreateLink(string path, string target, LinkType type) |
Creates a hard link, a junction or a symbolic link at path that points to target. |
ReparsePointProvider implements the interface, and its CreateHardLink, CreateJunction and CreateSymbolicLink methods are virtual.
Technically speaking a hard link is not a reparse point on Win32 systems: it is a type of file pointer supported since Windows XP and Windows Server 2003.
- Files only.
- Must be on the same volume and the same computer.
- No special privileges required, other than file security.
See Hard Links and Junctions for more information.
- Directories only, supported since Windows XP and Windows Server 2003.
- Resolved by the server, not the client.
- Can be on a different volume, but must be on the same computer.
- No special privileges required, other than folder security.
See Hard Links and Junctions for more information.
- Files or directories, supported since Windows Vista and Windows Server 2008.
- Resolved by the client, not the server.
- Can be on a different volume or a different computer.
- Requires the
SeCreateSymbolicLinkPrivilegeright: administrator accounts have it by default, but must run elevated, and other accounts must be granted it in Local Security Policy.
See Symbolic Links for more information.
- Issues: report a bug or ask for a feature.
- CONTRIBUTING.md: how to set up, build, test and propose a change.
- SECURITY.md: how to report a vulnerability privately.
- CODE_OF_CONDUCT.md, GOVERNANCE.md and ROADMAP.md: how we work together, who decides, and where the project is going.
- docs/architecture.md and docs/assurance-case.md: how the project is built, and why it meets its security requirements.
- docs/decisions/: the decisions behind the design, the project's and the template's.
- docs/replies.md: the replies the maintainers post to people outside the project.
- CHANGELOG.md: what changed in each release, in the Keep a Changelog format.
- LICENSE.txt: the license.
NCode.ReparsePoints is licensed under the Apache License 2.0.
