views:

591

answers:

1

I wonder if there is a universal way of resolving a path using a drive letter (such as X:\foo\bar.txt) into its equivalent UNC path, which might be one of the following:

  • X:\foo\bar.txt if X: is a real drive (i.e. hard disk, USB stick, etc.)
  • \\server\share\foo\bar.txt if X: is a network drive mounted on \\server\share
  • C:\xyz\foo\bar.txt if X: is the result of a SUBST command mapping X: to C:\xyz

I know that there are partial solutions which will:

  1. Resolve a network drive (see for instance question 556649 which relies on WNetGetUniversalName)

  2. Resolve the SUBST drive letter (see QueryDosDevice which works as expected, but does not return UNC paths for things such as local drives or network drives).

Am I missing some straightforward way of implementing this drive letter resolution in Win32? Or do I really have to mess with both WNetGetUniversalName and QueryDosDevice to get what I need?

+1  A: 

Yes, you would need to resolve the drive letter independantly. WNetGetUniversalName() comes close, but only works for drive letters that are mapped to actual UNC shares, which is not always the case. There is no single API function that does all of the work for you.

Remy Lebeau - TeamB