Advertisement
2002C Files/ File Controls/ Input/ Output #11314

Get the UNC Path

Networked drives. They're an administrative nightmare. In fact, the average user changes his networked drive letters more often than his underwear. But you can solve this problem of binding an application to a particular drive by using a Universal Naming Convention (UNC) path. This still references a network area, but doesn’t tie it to any one drive letter. And you can retrieve and check the UNC of a particular path in code using this neat little function. To use it, simply call GetUNCPath, passing it your drive letter along with a pre-declared empty string. If a problem occurs, the relevant number is passed back with the function. These can be matched with the possible return code constants. However if everything goes swimmingly, the function returns a zero (a constant value of NO_ERROR) and places the UNC path into the ByRef-passed variable. This code works by making a call to the WNetGetConnection function in MPR.DLL. It's essentially a neat wrapper for a regular API call.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Dim strUNC As String
  If GetUNCPath("H:", strUNC) = NO_ERROR Then
    MsgBox "The UNC of the specified drive is " & strUNC
  Else
    MsgBox "There was a problem, sorry!"
  End If
Original Comments (3)
Recovered from Wayback Machine