This article is based on the article Manipulating NTFS Junction Points in .NET by Jeff Brown.
In Windows Vista, there are a lot of directory links.
For example: The link C:\Documents and Settings opens the target directory C:\Users.
When I was writing my own directory browser for Windows Vista, I stumbled across these directory links.
How should I retrieve the target directory from such a directory link?
This article describes how.
The NTFS file system saves the link information in a so called "reparse point",
REPARSE_GUID_DATA_BUFFER structure (See Platform SDK for details).
To read this "reparse point" out of a directory link, you have to open it as a file,
CreateFile function without any special access permissions.
If you have successfully opened the file,
you can read the
REPARSE_GUID_DATA_BUFFER structure by calling
and then get the target directory out of it.
Using the Code
ReparsePoint.GetTargetDir method like this:
String linkDir = "C:\\Documents and Settings";
DirectoryInfo directoryInfo = new DirectoryInfo(linkDir);
String targetDir = ReparsePoint.GetTargetDir(directoryInfo);
if (targetDir == "")
#region "DllImports, Constants & Structs"
private const Int32 INVALID_HANDLE_VALUE = -1;
private const Int32 OPEN_EXISTING = 3;
private const Int32 FILE_FLAG_OPEN_REPARSE_POINT = 0x200000;
private const Int32 FILE_FLAG_BACKUP_SEMANTICS = 0x2000000;
private const Int32 FSCTL_GET_REPARSE_POINT = 0x900A8;
Points of Interest
It took me a lot of time to find out why Windows Vista always denied me access
to the reparse points of all my directory links.
The reason was that I used the
GENERIC_READ constant as
CreateFile function, and that would require a higher access permission.
But with a value of
0 (no special access permissions) it works!
This project would not have been possible without the assistance of others in the community.
I consulted the following references while implementing this functionality in .NET:
- 8/17/2007: Initial post to CodeProject