Page 2 of 2

Re: Convert mapped drive to UNC

Posted: Wed May 05, 2010 8:38 am
by hostonmark
This is very simple.A call to WNetGetConnection API returns the UNC name for any drive letter, most drives typically are not mapped.

I've put together a loop that calls a DriveLetterToUNC function on each letter of the alphabet from C to Z,prepares an adequate buffer by creating a string that's MAX_PATH characters long, then passes this string with the buffer length and drive letter to WNetGetConnection.

Your code extracts the UNC name from the buffer by scanning for the first Null character and trimming just before it.