Exemplo n.º 1
0
        private string getDiskLetter(Guid uniqueGuid)
        {
            DriveType driveType;

            char[] NamesBuff = new char[128];

            WinApi.GetLogicalDriveStrings(128, NamesBuff);
            char[] DriveName = new char[4];

            for (int BuffOffset = 0; BuffOffset < NamesBuff.Length; BuffOffset += 4)
            {
                //-----cut drive name from string with drive names------------
                for (int NameOffset = 0; NameOffset < 4; NameOffset++)
                {
                    DriveName[NameOffset] = NamesBuff[NameOffset + BuffOffset];
                }
                //-------------------------------------------------------------

                if (DriveName[0] == '\0')
                {
                    DriveName[0] = '*'; DriveName[1] = ':'; DriveName[2] = '\\'; DriveName[3] = '\0';
                    break;
                }

                //--------------
                driveType = WinApi.GetDriveType(new String(DriveName));

                if (driveType == DriveType.Fixed || driveType == DriveType.Removable)
                {
                    string guidOfDrive;
                    guidOfDrive = WinApi.GetVolumeName(new String(DriveName));
                    guidOfDrive = guidOfDrive.Substring(11);                    //del beg
                    guidOfDrive = guidOfDrive.Remove((guidOfDrive.Length - 2)); //del end

                    if (uniqueGuid.ToString() == guidOfDrive)
                    {
                        return(new String(DriveName));
                    }
                }
                //--------------
            }
            return(new String(DriveName));
        }