示例#1
0
        // --------------------------------------------------------------------------- -------------
        // Class Name:  VolumeFunctions
        // Procedure Name: UnmapFolderFromDrive
        // Purpose:   Unmap a drive letter. We always unmp the drive, without checking the
        //                  folder name.
        // Parameters:
        //  - driveLetter (string)  :   Drive letter to be released, the the format "C:"
        //  - folderName (string)  :    Folder name that the drive is mapped to.
        // --------------------------------------------------------------------------- -------------
        internal static string UnmapFolderFromDrive(string driveLetter, string folderName)
        {
            DefineDosDevice(DDD_REMOVE_DEFINITION, driveLetter, folderName);
            // Display the status of the "last" unmap we run.
            string statusMessage = new Win32Exception(Marshal.GetLastWin32Error()).ToString();

            return(statusMessage.Substring(statusMessage.IndexOf(":") + 1));
        }
示例#2
0
        // --------------------------------------------------------------------------- -------------
        // Class Name:  VolumeFunctions
        // Procedure Name: MapFolderToDrive
        // Purpose:   Map the folder to a drive letter
        // Parameters:
        //  - driveLetter (string)  : Drive letter in the format "C:" without a back slash
        //  - folderName (string)  : Folder to map without a back slash
        // --------------------------------------------------------------------------- -------------
        internal static string MapFolderToDrive(string driveLetter, string folderName)
        {
            // Is this drive already mapped? If so, we don't remap it!
            StringBuilder volumeMap = new StringBuilder(1024);

            QueryDosDevice(driveLetter, volumeMap, (uint)1024);
            if (volumeMap.ToString().StartsWith(MAPPED_FOLDER_INDICATOR) == true)
            {
                return("Volume is already mapped - map not changed");
            }
            // Map the folder to the drive
            DefineDosDevice(0, driveLetter, folderName);
            // Display a status message to the user.
            string statusMessage = new Win32Exception(Marshal.GetLastWin32Error()).ToString();

            return(statusMessage.Substring(statusMessage.IndexOf(":") + 1));
        }