DefineDosDevice() 개인적인 메소드

private DefineDosDevice ( [ dwFlags, [ lpDeviceName, [ lpTargetPath ) : bool
dwFlags [
lpDeviceName [
lpTargetPath [
리턴 bool
예제 #1
0
        /// <summary>
        /// Remove the drive substitution.
        /// </summary>
        public void Dispose()
        {
            if (null != this.DriveLetter)
            {
                SubstituteDrive.DefineDosDevice(DefineDosDeviceFlags.RemoveExactMatch, this.DriveLetter, this.TargetPath);

                this.DriveLetter = null;
                this.TargetPath  = null;

                GC.SuppressFinalize(this);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubstituteDrive"/> class.
        /// </summary>
        /// <param name="driveLetter">The drive letter to use for the substitution.</param>
        /// <param name="targetPath">The path to the folder to map to a drive letter.</param>
        /// <exception cref="ArgumentException">The <paramref name="driveLetter"/> is already defined.</exception>
        /// <exception cref="Win32Exception">An error occurred when creating a drive subistution.</exception>
        internal SubstituteDrive(char driveLetter, string targetPath)
        {
            Contract.Requires('C' <= driveLetter && 'Z' >= driveLetter);
            Contract.Requires(!string.IsNullOrEmpty(targetPath));

            driveLetter = char.ToUpperInvariant(driveLetter);
            if (SubstituteDrive.IsDefined(driveLetter))
            {
                throw new ArgumentException("The drive letter is already defined.", "driveLetter");
            }

            this.DriveLetter = driveLetter + ":";
            this.TargetPath  = targetPath;

            if (!SubstituteDrive.DefineDosDevice(DefineDosDeviceFlags.None, this.DriveLetter, this.TargetPath))
            {
                // Throw last error.
                throw new Win32Exception();
            }
        }