Get mapped network drives on local machine

This is a discussion on Get mapped network drives on local machine within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, I'm looking for a function to convert an absolute path to UNC and UNC to an absolute path ...

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139

    Get mapped network drives on local machine

    Hi all,

    I'm looking for a function to convert an absolute path to UNC and UNC to an absolute path ( if possible ).

    Example:

    John types "X:\Folder\File.ext" on his computer.

    A function converts it to "\\Server\Share\Folder\File.ext" and saves it in a central place.

    Jane accesses the information on her workstation. She has "\\Server\Share" mapped to L:

    A function converts it to "L:\Folder\File.ext".

    ( Obviously it's not that easy, things can fail, special considerations need to be taken into account, maybe drives aren't mapped that way at all etc )


    I already got the "AbsoluteToUNC" conversion done. Works like a charm. However, I'm still looking for a function that can list all mapped drives and targets of that mappings for the local workstation.

    Anyone got any ideas ? I already looked through all the Netx functions and examples on MSDN, but all of them only work the other way, listing shares of the local machine.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Are you looking for something like the following?

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
    	DWORD	dwDrives;
    	UINT	uDriveType;
    	int	iDrive;
    	char	szDrive[_MAX_DRIVE + 1];
    
    	dwDrives = GetLogicalDrives();
    
    	printf("The following is a list of network drives\n");
    	for(iDrive = 0; iDrive < 26; iDrive++)
    	{
    		sprintf(szDrive,"%c:\\",iDrive + 'A');
    
    		uDriveType = GetDriveType(szDrive);    
    		
    		if(uDriveType == DRIVE_REMOTE)
    		{
    			printf("%s\n",szDrive);
    		}
    	}
    	return 0;
    }
    Last edited by bithub; 10-19-2004 at 02:21 AM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Quote Originally Posted by nvoigt
    a function that can list all mapped drives and targets of that mappings for the local workstation.
    Have you had a look at the WNet APIs?

    Especially WNetEnumResource.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Ah, thanks a lot, I will try this tomorrow morning
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. establishing a local area network (two servers and clients)
    By shrijeetp in forum Networking/Device Communication
    Replies: 3
    Last Post: 09-10-2005, 06:17 AM
  3. Mapping network drives
    By Morgan in forum Windows Programming
    Replies: 4
    Last Post: 07-19-2004, 04:07 AM
  4. Local Area Network Browsing
    By devour89 in forum Networking/Device Communication
    Replies: 0
    Last Post: 08-16-2003, 12:00 PM
  5. Replies: 8
    Last Post: 01-09-2003, 09:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21