public static void CreateFileLink(string linkPath, string targetPath) { if (!Win32SafeNativeMethods.CreateSymbolicLink(linkPath, targetPath, TargetIsAFile)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } }
public static void CreateDirectoryLink(string linkPath, string targetPath) { if (Win32SafeNativeMethods.CreateSymbolicLink(linkPath, targetPath, TargetIsADirectory) && Marshal.GetLastWin32Error() == 0) { return; } try { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } catch (COMException exception) { throw new IOException(exception.Message, exception); } }