NtOpenSymbolicLinkObject (ntdll)
Last changed: anonymous

.
Summary
Opens an existing symbolic link.

C# Signature:

[DllImport("ntdll.dll")]
public static extern int NtOpenSymbolicLinkObject(
   out SafeFileHandle LinkHandle,
   uint DesiredAccess,
   ref OBJECT_ATTRIBUTES ObjectAttributes);

User-Defined Types:

OBJECT_ATTRIBUTES

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

cf. NtOpenDirectoryObject

Tips & Tricks:

Please add some!

Sample Code:

static string GetSymbolicLinkTarget(string name)
{
   SafeFileHandle h;
   var attr = new OBJECT_ATTRIBUTES(name, 0);
   var st = Win32.NtOpenSymbolicLinkObject(
     out h, 0x80000000/*GENERIC_READ*/, ref attr);
   if (st < 0) return null;

   int len;
   var buf = new UNICODE_STRING(new string(' ', 512));
   st = Win32.NtQuerySymbolicLinkObject(h, ref buf, out len);

   h.Dispose();
   if (st < 0) return null;
   return buf.ToString();
}

cf. NtQuerySymbolicLinkObject

Documentation