Results 1 to 3 of 3

Thread: Network connection problem..!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Skövde,Sweden
    Posts
    4

    Talking

    Hi there!
    I have a problem with network connections. I'd like to know if there is a way to find/use files within the network without specifying the drive. ex \\server01\program\ instead of E:\program . The reason is that users connects the server on different drives. Any suggestions?

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    There must be an easier way, but I suppose that if you know the server path, and all you need is the drive letter that is attached to it, you could use something like this:

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_NORMAL = 1
    
    
    
    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
    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 = "Drive Letter Not Found"
    
    'Check for success from  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
    LetterToUNC = UNCName
    
    ' Exit the loop
    Exit For
    End If
    Next i
    End If
    End If
    
    ' End enumeration
    nStatus = WNetCloseEnum(hEnum)
    End Function
    
    'Now use the FileSystemObject to get the 
    'drives collection
    
    Private Sub Command1_Click()
    
      Dim CheckDrive As String
      Dim fso, sdrive, sdrivecoll
      Dim s As String
      
    
      Set fso = CreateObject("Scripting.FileSystemObject")
    
      Set sdrivecoll = fso.Drives
    
      'Loop through collection
       For Each sdrive In sdrivecoll
        
        'set drive letter
        s = sdrive.DriveLetter & ":"
        
        'convert drive letter to UNC
        'and check against path
        CheckDrive = LetterToUNC(s)
        CheckDrive = Trim(CheckDrive)
            
            'If paths are = then shell the app.
            If CheckDrive = "\\CSP2\SPACE\IS" Then
                lresult = ShellExecute(0&, "open", CheckDrive & "\Library\Shared\Eserials.xls", vbNullString, 0&, 1)
                Exit For
            End If
            
        
      Next
    
    
    
    
    
    End Sub
    Hope this helps.

    (Using VB6 SP3)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Skövde,Sweden
    Posts
    4
    OK! I see.. Thanx
    Is there any way too get access to files within the network
    without the user has too connect it to a driveletter??
    When I code in LISP I can use specified names such as
    \\AcadServer01\program\R14\textfile.txt to find the file
    textfile.txt without connecting a specific drive to this
    connection.??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width