Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the UNC Path of CurrentProject

Status
Not open for further replies.

benkarl

Programmer
Nov 14, 2002
4
US
Is there a simple way to get the UNC path of the current project? When I do Application.CurrentProject.Path, I get the path using the mapped drive letter and I want the UNC path.

The reason I need the UNC path is that various users will have different drive letters mapped for the share the application will be located at and some will not have it mapped at all. I'm trying to detect if users are running the application from the 'master distribution' copy rather than from a local copy on their workstations and display a message if they are. I store the current location of the master distribution copy in a table to compare with the current path, if they match, the user is in the master copy and I can display my message but that only works with the UNC path.

Any suggestions?

Thank you.
 
Referencing the Windows Script Host Object Model you can play with the WshNetwork object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
benkarl,

This may help

Create a new module, with the following in the Declarations section:

Code:
Option Explicit

' These represent the possible returns errors from API.
Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_MORE_DATA = 234
Public Const ERROR_NOT_SUPPORTED = 50&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_NOT_CONNECTED = 2250&
Public Const NO_ERROR = 0

' This API declaration is used to return the
' UNC path from a drive letter.

Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long

Then create this Function..

Code:
Function GetUNCPath(strDriveLetter As String) As String
   On Local Error GoTo GetUNCPath_Err
   Dim Msg As String, lngReturn As Long
   Dim lpszLocalName As String
   Dim lpszRemoteName As String
   Dim cbRemoteName As Long
   lpszLocalName = strDriveLetter
   lpszRemoteName = String$(255, Chr$(32))
   cbRemoteName = Len(lpszRemoteName)
   lngReturn = WNetGetConnection(lpszLocalName,  lpszRemoteName, cbRemoteName)
   Select Case lngReturn
      Case ERROR_BAD_DEVICE
         Msg = "Error: Bad Device"
      Case ERROR_CONNECTION_UNAVAIL
         Msg = "Error: Connection Un-Available"
      Case ERROR_EXTENDED_ERROR
         Msg = "Error: Extended Error"
      Case ERROR_MORE_DATA
         Msg = "Error: More Data"
      Case ERROR_NOT_SUPPORTED
         Msg = "Error: Feature not Supported"
      Case ERROR_NO_NET_OR_BAD_PATH
         Msg = "Error: No Network Available or Bad Path"
      Case ERROR_NO_NETWORK
         Msg = "Error: No Network Available"
      Case ERROR_NOT_CONNECTED
         Msg = "Error: Not Connected"
      Case NO_ERROR
         ' all is successful...
   End Select
   If Len(Msg) Then
      MsgBox Msg, vbInformation
   Else
      ' Display the path in a Message box or return
      ' the UNC through the function.
      MsgBox Left$(lpszRemoteName, cbRemoteName)
      GetUNCPath = Left$(lpszRemoteName, cbRemoteName)
   End If
GetUNCPath_End:
   Exit Function
GetUNCPath_Err:
   MsgBox Err.Description, vbInformation
   Resume GetUNCPath_End

Test with this
Code:
?GetUNCPath("h:")

I hope this works for you..

[thumbsup2]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top