Search code examples
c++windowsip-addressmapped-drive

How can I find the IP address of a mapped network drive in C++?


I have a list of possible paths to use for a default input data directory (X:\Data; Y:\Data; Z:\Data). All of the possible paths are mapped network drives. I can check this using GetDriveType(pathStr) == DRIVE_REMOTE. To determine the best one, I have narrowed down the list by selecting only paths that exist. Sometimes there will be more than one path left in the list, so to determine the best one at that point, I want to find the IP address of the server that the drive is mapped to, so I can compare it to my own IP address. For instance, if I have X:\ mapped to \\RemoteComputer\ShareName, how can I find out from the string X:\Data either the name or IP address of RemoteComputer? (I already have the ability to find the IP address from a computer name).


Solution

  • WNetGetUniversalName is one possibility.