winapinetwork-programmingresolvedrive-lettersubst

Resolve Windows drive letter to a path (subst and network)


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:

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?


Solution

  • Yes, you would need to resolve the drive letter independently.

    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.