public static void CreateSymbolicLinkTransacted(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType)
 {
     CreateSymbolicLinkCore(transaction, symlinkFileName, targetFileName, targetType, PathFormat.RelativePath);
 }
        internal static void CreateSymbolicLinkCore(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
        {
            if (!NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(Resources.Requires_Windows_Vista_Or_Higher);
            }

            var options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;

            string symlinkFileNameLp = Path.GetExtendedLengthPathCore(transaction, symlinkFileName, pathFormat, options);
            string targetFileNameRp  = Path.GetExtendedLengthPathCore(transaction, targetFileName, pathFormat, options);

            // Don't use long path notation, as it will be empty upon creation.
            targetFileNameRp = Path.GetRegularPathCore(targetFileNameRp, GetFullPathOptions.None, false);


            if (!(transaction == null

                  // CreateSymbolicLink() / CreateSymbolicLinkTransacted()
                  // In the ANSI version of this function, the name is limited to MAX_PATH characters.
                  // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
                  // 2014-02-14: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
                  // 2015-07-17: This function does not support long paths.

            ? NativeMethods.CreateSymbolicLink(symlinkFileNameLp, targetFileNameRp, targetType)
            : NativeMethods.CreateSymbolicLinkTransacted(symlinkFileNameLp, targetFileNameRp, targetType, transaction.SafeHandle)))
            {
                var lastError = Marshal.GetLastWin32Error();
                if (lastError != 0)
                {
                    NativeError.ThrowException(lastError, symlinkFileNameLp, targetFileNameRp);
                }
            }
        }
 public static void CreateSymbolicLink(string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType)
 {
     CreateSymbolicLinkCore(null, symlinkFileName, targetFileName, targetType, PathFormat.RelativePath);
 }
예제 #4
0
파일: NativeMethods.cs 프로젝트: CDEApp/CDE
 static internal extern bool CreateSymbolicLinkTransactedW([In] string lpSymlinkFileName, [In] string lpTargetFileName, [In, MarshalAs(UnmanagedType.U4)] SymbolicLinkTarget dwFlags, SafeHandle hTransaction);
예제 #5
0
        internal static void CreateSymbolicLinkCore(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
        {
            if (!NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(new Win32Exception((int)Win32Errors.ERROR_OLD_WIN_VERSION).Message);
            }


            if (pathFormat != PathFormat.LongFullPath)
            {
                const GetFullPathOptions options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;

                symlinkFileName = Path.GetExtendedLengthPathCore(transaction, symlinkFileName, pathFormat, options);
                targetFileName  = Path.GetExtendedLengthPathCore(transaction, targetFileName, pathFormat, options);
            }


            // Don't use long path notation, as it will be empty upon creation.
            targetFileName = Path.GetRegularPathCore(targetFileName, GetFullPathOptions.None, false);


            if (targetType == SymbolicLinkTarget.Directory)
            {
                ThrowIOExceptionIfFsoExist(transaction, false, targetFileName, pathFormat);
                ThrowIOExceptionIfFsoExist(transaction, false, symlinkFileName, pathFormat);
            }

            else
            {
                ThrowIOExceptionIfFsoExist(transaction, true, targetFileName, pathFormat);
                ThrowIOExceptionIfFsoExist(transaction, true, symlinkFileName, pathFormat);
            }


            var success = null == transaction

                          // CreateSymbolicLink() / CreateSymbolicLinkTransacted()
                          // 2014-02-14: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
                          // 2015-07-17: This function does not support long paths.
                          // 2017-05-30: CreateSymbolicLink() MSDN confirms LongPath usage: Starting with Windows 10, version 1607

            ? NativeMethods.CreateSymbolicLink(symlinkFileName, targetFileName, targetType)
            : NativeMethods.CreateSymbolicLinkTransacted(symlinkFileName, targetFileName, targetType, transaction.SafeHandle);


            var lastError = (uint)Marshal.GetLastWin32Error();

            if (!success)
            {
                NativeError.ThrowException(lastError, targetFileName, symlinkFileName);
            }
        }
        internal static void CreateSymbolicLinkInternal(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
        {
            var options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;

            string symlinkFileNameLp = Path.GetExtendedLengthPathInternal(transaction, symlinkFileName, pathFormat, options);
            string targetFileNameLp  = Path.GetExtendedLengthPathInternal(transaction, targetFileName, pathFormat, options);

            if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista

                  // CreateSymbolicLink() / CreateSymbolicLinkTransacted()
                  // In the ANSI version of this function, the name is limited to MAX_PATH characters.
                  // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
                  // 2014-02-14: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

            ? NativeMethods.CreateSymbolicLink(symlinkFileNameLp, targetFileNameLp, targetType)
            : NativeMethods.CreateSymbolicLinkTransacted(symlinkFileNameLp, targetFileNameLp, targetType, transaction.SafeHandle)))
            {
                NativeError.ThrowException(symlinkFileNameLp, targetFileNameLp);
            }
        }
예제 #7
0
파일: NativeMethods.cs 프로젝트: CDEApp/CDE
 static internal extern bool CreateSymbolicLinkW([In] string lpFileName, [In] string lpExistingFileName, [In, MarshalAs(UnmanagedType.U4)] SymbolicLinkTarget dwFlags);
 public static void CreateSymbolicLink(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
 {
     CreateSymbolicLinkInternal(transaction, symlinkFileName, targetFileName, targetType, pathFormat);
 }
 public static void CreateSymbolicLink(string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
 {
     CreateSymbolicLinkInternal(null, symlinkFileName, targetFileName, targetType, pathFormat);
 }
예제 #10
0
      internal static void CreateSymbolicLinkInternal(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType, PathFormat pathFormat)
      {
         var options = GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.FullCheck;

         string symlinkFileNameLp = Path.GetExtendedLengthPathInternal(transaction, symlinkFileName, pathFormat, options);
         string targetFileNameLp = Path.GetExtendedLengthPathInternal(transaction, targetFileName, pathFormat, options);

         if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista

            // CreateSymbolicLink() / CreateSymbolicLinkTransacted()
            // In the ANSI version of this function, the name is limited to MAX_PATH characters.
            // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
            // 2014-02-14: MSDN does not confirm LongPath usage but a Unicode version of this function exists.

            ? NativeMethods.CreateSymbolicLink(symlinkFileNameLp, targetFileNameLp, targetType)
            : NativeMethods.CreateSymbolicLinkTransacted(symlinkFileNameLp, targetFileNameLp, targetType, transaction.SafeHandle)))
            NativeError.ThrowException(symlinkFileNameLp, targetFileNameLp);
      }
예제 #11
0
 public static void CreateSymbolicLink(KernelTransaction transaction, string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType)
 {
    CreateSymbolicLinkInternal(transaction, symlinkFileName, targetFileName, targetType, PathFormat.RelativePath);
 }
예제 #12
0
 public static void CreateSymbolicLink(string symlinkFileName, string targetFileName, SymbolicLinkTarget targetType)
 {
    CreateSymbolicLinkInternal(null, symlinkFileName, targetFileName, targetType, PathFormat.RelativePath);
 }