Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapped drives

Status
Not open for further replies.

dds82

Programmer
Jun 5, 2002
251
US
If I have a complete path name to a network shared folder (like \\computer\folder), can I find out if the current user has that folder mapped to a drive?

Thanks.
 
Try This:

Code:
void ListValidDrives()
{
   int drives = GetLogicalDrives();

   for(int i = 2;i<26;i++)
   {
     CString temp;
     temp.Format(&quot;%c:\\&quot;,'A'+i);
     unsigned int type = GetDriveType(temp);
     
     if(drives>>i & 1)
     {
        if(type & DRIVE_REMOTE)
        {
            // mapped drive
        }
     }
   }
}

Matt


 
That will get me a list of the mapped drives. My question was, how do I tell where a drive is mapped to?
 
Sorry, once you know the drive letter, Use the letter for the key value under

HKEY_CURRENT_USER\Network\<DRIVE LETTER>

If I remember correctly, and as the key value suggests, these should all be network drives.

Matt
 
Thanks! Just what I was looking for.

One small change to your code, though...

GetDriveType() doesn't return a bitmask, it returns a value. So change

if(type & DRIVE_REMOTE)

to

if(type == DRIVE_REMOTE)

and everything works fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top