Skip to content

About

This library provides functions to manage Win32 Reparse Points such as Symbolic Links, Hard Links, and Junctions.

Resources

Code of conduct

Contributing

Security policy

Stars

12 stars

Watchers

1 watching

Forks

Latest commit

 

History

63 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NCode Group

NCode.ReparsePoints

Create and inspect Win32 file and folder reparse points such as hard links, junctions and symbolic links.

NuGet version NuGet downloads CI Target framework License OpenSSF Scorecard

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.

Installation

Add the package to a project:

dotnet add package NCode.ReparsePoints

Quick start

using 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);
    }
}

Usage

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.

Hard link

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.

Junction

  • 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.

Symbolic link

  • 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 SeCreateSymbolicLinkPrivilege right: 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.

Project

License

NCode.ReparsePoints is licensed under the Apache License 2.0.

About

This library provides functions to manage Win32 Reparse Points such as Symbolic Links, Hard Links, and Junctions.

Resources

Code of conduct

Contributing

Security policy

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages