?
Solved

How to get the drive mapping from a drive letter?

Posted on 2003-03-20
2
Medium Priority
?
184 Views
Last Modified: 2010-05-01
I need to get the drive mapping of a specific drive letter.  

i.e.  I provide "F" and the function returns "//blah/blahblah"

The catch is, I can't use Microsoft Scripting Runtime as a resource.  I would preferably like to do this using on of the following Reference Libraries:

Visual Basic for Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures

OR using an API function

Why not use Microsoft Scripting Runtime you ask?  Because I'm trying to compile an executable on an NT4 Server and I don't want to install it.  I just want to compile an executable and move it to a directory.  If I reference MSR I get a Object Error when I try to run it on NT4.  I tried installing the application by creating a package but it ended up causing problems.  We couldn't get the server to respond after rebooting.

Any help would be greatly appreciated.
0
Comment
Question by:jbauer22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 1000 total points
ID: 8176668
Originally by GivenRandy:

Const lBUFFER_SIZE As Long = 255

Private Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, lSize As Long) As Long

Private Sub Command1_Click()
   MsgBox UNC("F:")  ' only the first letter of the pathname is required
End Sub

Private Function UNC(Pathname As String) As String
   UNC = Space(lBUFFER_SIZE)
   WNetGetConnection32 Left$(Pathname, 1) & ":", UNC, lBUFFER_SIZE
End Function
0
 
LVL 2

Author Comment

by:jbauer22
ID: 8177446
Awesome.

Here's my function

Public Function GetMapping(ByVal strDrive As String) As String
   
    Dim strMapping As String * 255
    Dim lngLength As Long
   
    '--- Set Drive letter to proper format
    strDrive = Left(strDrive, 1) & ":"
   
    '--- Get Lenth of Buffer
    lngLength = Len(strMapping)
   
    '--- Get Mapping
    WNetGetConnection strDrive, strMapping, lngLength
   
    '--- Remove Nulls
    GetMapping = NV(strMapping)
   
End Function


'--- I use this globally
Public Function NV(varValue As Variant) As String

    If (InStr(varValue, Chr(0)) > 0) Then
        varValue = Left(varValue, InStr(varValue, Chr(0)) - 1)
    ElseIf IsNull(varValue) Then
        varValue = ""
    End If

    NV = varValue
   
End Function
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question