determining host from a logical drive letter? 
Author Message
 determining host from a logical drive letter?

not sure if this is a simple question question ( yeh yeh the answers the
difficult part), but here goes.

I want my program to determine the host (server name) from a given drive
letter. can and how would you do this in VB?

The program will run on a users machine who sets their own drive mappings. I
only want to determin the host name associated with the letter

 example 1. (networked)

 a user may have mapped drive H: to \\HOSTX\DIRY. I want a general solution
which will ideally be protocol independent which should return HOSTX

example 2 (stand alone)

the users machine is not networked but given that I want to return the host
name associated with drive D: the call cannot assume drive D: is not a
networked drive



Wed, 16 May 2001 03:00:00 GMT  
 determining host from a logical drive letter?
Look at WNetGetConnection - given a drive letter, returns the mapping (if
any).

--
     Jim Mack
     MicroDexterity, Inc

     http://www.microdexterity.com




Quote:
>not sure if this is a simple question question ( yeh yeh the answers the
>difficult part), but here goes.

>I want my program to determine the host (server name) from a given drive
>letter. can and how would you do this in VB?

>The program will run on a users machine who sets their own drive mappings.
I
>only want to determin the host name associated with the letter

> example 1. (networked)

> a user may have mapped drive H: to \\HOSTX\DIRY. I want a general solution
>which will ideally be protocol independent which should return HOSTX

>example 2 (stand alone)

>the users machine is not networked but given that I want to return the host
>name associated with drive D: the call cannot assume drive D: is not a
>networked drive



Wed, 16 May 2001 03:00:00 GMT  
 determining host from a logical drive letter?
Quote:

>Not real easy to do.
<cut>


>>I want my program to determine the host (server name) from a given drive
>>letter. can and how would you do this in VB?

<cut>

Real easy to do...  see
http://home.earthlink.net/~butlerbob/vb/disk/drives.htm



Wed, 16 May 2001 03:00:00 GMT  
 determining host from a logical drive letter?
Try this , it will retrieve a unc name from a passed logical drive or pass
back the logical if there isnt one
Attribute VB_Name = "modGetUnc"
Option Explicit

Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_CONNECTED = &H1

Private Type NETRESOURCE
    dwScope As Long
    dwType As Long
    dwDisplayType As Long
    dwUsage As Long
    lpLocalName As Long
    lpRemoteName As Long
    lpComment As Long
    lpProvider As Long
End Type

Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias _
        "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, _
        ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) _
        As Long

Private Declare Function WNetEnumResource Lib "mpr.dll" Alias _
        "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, _
        lpBuffer As Any, lpBufferSize As Long) As Long

Private Declare Function WNetCloseEnum Lib "mpr.dll" ( _
        ByVal hEnum As Long) As Long

Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
        (ByVal lpString As Any) As Long

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
        (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long

Function LetterToUNC(DriveLetter As String) As String
'Returns UNC or Drive letter depending if one exists
    Dim hEnum As Long
    Dim NetInfo(1023) As NETRESOURCE
    Dim entries As Long
    Dim nStatus As Long
    Dim LocalName As String
    Dim UNCName As String
    Dim i As Long
    Dim r As Long

    ' Begin the enumeration
    nStatus = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, _
            0&, ByVal 0&, hEnum)

    LetterToUNC = DriveLetter

    'Check for success from open enum
    If ((nStatus = 0) And (hEnum <> 0)) Then
        ' Set number of entries
        entries = 1024

        ' Enumerate the resource
        nStatus = WNetEnumResource(hEnum, entries, NetInfo(0), _
                CLng(Len(NetInfo(0))) * 1024)

        ' Check for success
        If nStatus = 0 Then
            For i = 0 To entries - 1
                ' Get the local name
                LocalName = ""
                If NetInfo(i).lpLocalName <> 0 Then
                    LocalName = Space(lstrlen(NetInfo(i).lpLocalName) + 1)
                    r = lstrcpy(LocalName, NetInfo(i).lpLocalName)
                End If

                ' Strip null character from end
                If Len(LocalName) <> 0 Then
                    LocalName = Left(LocalName, (Len(LocalName) - 1))
                End If

                If UCase$(LocalName) = UCase$(DriveLetter) Then
                    ' Get the remote name
                    UNCName = ""
                    If NetInfo(i).lpRemoteName <> 0 Then
                        UNCName = Space(lstrlen(NetInfo(i).lpRemoteName) _
                                + 1)
                        r = lstrcpy(UNCName, NetInfo(i).lpRemoteName)
                    End If

                    ' Strip null character from end
                    If Len(UNCName) <> 0 Then
                        UNCName = Left(UNCName, (Len(UNCName) _
                                - 1))
                    End If

                    ' Return the UNC path to drive
                    'added the [] to seperate on printout only
                    LetterToUNC = UNCName

                    ' Exit the loop
                    Exit For
                End If
            Next i
        End If
    End If

    ' End enumeration
    nStatus = WNetCloseEnum(hEnum)
End Function

Regard's
Donald Grover

T.A.M.E.S.?  A Tooling and Moulding Estimation System
Australian Scientific Software.


Quote:
>not sure if this is a simple question question ( yeh yeh the answers the
>difficult part), but here goes.

>I want my program to determine the host (server name) from a given drive
>letter. can and how would you do this in VB?

>The program will run on a users machine who sets their own drive mappings.
I
>only want to determin the host name associated with the letter

> example 1. (networked)

> a user may have mapped drive H: to \\HOSTX\DIRY. I want a general solution
>which will ideally be protocol independent which should return HOSTX

>example 2 (stand alone)

>the users machine is not networked but given that I want to return the host
>name associated with drive D: the call cannot assume drive D: is not a
>networked drive



Thu, 17 May 2001 03:00:00 GMT  
 determining host from a logical drive letter?
Bob please think about your answer again.
    If you have good knowledge of the api you can find the host because it is
a property of a drive letter on a particular machine. I do not know the
necessary function , but since properties of nearly everything system wise is
accessible just keep looking.
Quote:


> >Not real easy to do.
> <cut>


> >>I want my program to determine the host (server name) from a given drive
> >>letter. can and how would you do this in VB?
> <cut>

> Real easy to do...  see
> http://home.earthlink.net/~butlerbob/vb/disk/drives.htm



Fri, 18 May 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. determining host from a logical drive letter?

2. Obtaining logical drive letter of LAN server

3. Logical Drive Letter to UNC Conversion

4. Determining drive letter assigned to floppy drive?

5. Determine CD drive letter

6. Use VB4 to determine CD-ROM drive letter?

7. How do I determine the current drive letter?

8. Drive letter driving me crazy!

9. Retrieving drive letter for user's cd-rom drive

10. local drive letter <> drive share name

11. searching logical drives for cdfs

12. How can I obtain the Net Path from a logical drive

 

 
Powered by phpBB® Forum Software