public static void DefineDosDevice(string deviceName, string targetPath, DosDeviceAttributes deviceAttributes) { DefineDosDeviceInternal(true, deviceName, targetPath, deviceAttributes, false); }
internal static void DefineDosDeviceInternal(bool isDefine, string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch) { if (Utils.IsNullOrWhiteSpace(deviceName)) throw new ArgumentNullException("deviceName"); if (isDefine) { // targetPath is allowed to be null. // In no case is a trailing backslash ("\") allowed. deviceName = Path.GetRegularPathInternal(deviceName, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars); // ChangeErrorMode is for the Win32 SetThreadErrorMode() method, used to suppress possible pop-ups. using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors)) if (!NativeMethods.DefineDosDevice(deviceAttributes, deviceName, targetPath)) NativeError.ThrowException(deviceName, targetPath); } else { // A pointer to a path string that will implement this device. // The string is an MS-DOS path string unless the DDD_RAW_TARGET_PATH flag is specified, in which case this string is a path string. if (exactMatch && !Utils.IsNullOrWhiteSpace(targetPath)) deviceAttributes = deviceAttributes | DosDeviceAttributes.ExactMatchOnRemove | DosDeviceAttributes.RawTargetPath; // Remove the MS-DOS device name. First, get the name of the Windows NT device // from the symbolic link and then delete the symbolic link from the namespace. DefineDosDevice(deviceName, targetPath, deviceAttributes); } }
public static void DeleteDosDevice(string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch) { DefineDosDeviceInternal(false, deviceName, targetPath, deviceAttributes, exactMatch); }
internal static extern bool DefineDosDevice(DosDeviceAttributes dwFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpDeviceName, [MarshalAs(UnmanagedType.LPWStr)] string lpTargetPath);
public static void DeleteDosDevice(string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch) { DefineDosDeviceCore(false, deviceName, targetPath, deviceAttributes, exactMatch); }
internal static void DefineDosDeviceCore(bool isDefine, string deviceName, string targetPath, DosDeviceAttributes deviceAttributes, bool exactMatch) { if (Utils.IsNullOrWhiteSpace(deviceName)) { throw new ArgumentNullException("deviceName"); } if (isDefine) { // targetPath is allowed to be null. // In no case is a trailing backslash ("\") allowed. deviceName = Path.GetRegularPathCore(deviceName, GetFullPathOptions.RemoveTrailingDirectorySeparator | GetFullPathOptions.CheckInvalidPathChars, false); using (new NativeMethods.ChangeErrorMode(NativeMethods.ErrorMode.FailCriticalErrors)) { var success = NativeMethods.DefineDosDevice(deviceAttributes, deviceName, targetPath); var lastError = Marshal.GetLastWin32Error(); if (!success) { NativeError.ThrowException(lastError, deviceName, targetPath); } } } else { // A pointer to a path string that will implement this device. // The string is an MS-DOS path string unless the DDD_RAW_TARGET_PATH flag is specified, in which case this string is a path string. if (exactMatch && !Utils.IsNullOrWhiteSpace(targetPath)) { deviceAttributes = deviceAttributes | DosDeviceAttributes.ExactMatchOnRemove | DosDeviceAttributes.RawTargetPath; } // Remove the MS-DOS device name. First, get the name of the Windows NT device // from the symbolic link and then delete the symbolic link from the namespace. DefineDosDevice(deviceName, targetPath, deviceAttributes); } }
public static void DefineDosDevice(string deviceName, string targetPath, DosDeviceAttributes deviceAttributes) { DefineDosDeviceCore(true, deviceName, targetPath, deviceAttributes, false); }