Results 1 to 5 of 5

Thread: Sharename on local machine??

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Geelong, Victoria, Australia
    Posts
    8
    Hi all,

    Does anyone know how to determine a sharename (UNC) given a file name on a local (fixed) drive.
    I am using the Scripting.FileSystemObject which works brilliantly for network (remote) drives but won't return a share name for local drives/files.
    (e.g. c:\my documents\myletter.doc)

    This is further complicated if only some folders on the local machine are shared.

    Any help or comments would be greatly appreciated.

    Stu.



    Stu.

  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Not help, just a comment:

    A UNC name will usually include a reference to a shared folder and file name accessible over a network rather than specifying a drive letter and path. For example, to access a database named Northwind.mdb on a shared directory named Samples on the computer called MyWorkstation, you could use the UNC name \\MyWorkstation\Samples\Northwind.mdb.

    What are you trying to do? Is it get the sharename where the file resides? Or have I missed the point entirely?


  3. #3
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Had a thought about this, try this code. Can do lots of stuff here, by defining constants for various drive types (Floppy/CD etc) rather than the on_error hack I've shown. If this is going down the right road, let me know as I have more detailed info I can give you.


    Private Sub Command1_Click()
    ShowDriveList
    End Sub
    '
    '
    Sub ShowDriveList()
    On Error GoTo err_handler

    Dim fs, d, dc, s, n
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set dc = fs.Drives
    For Each d In dc
    s = s & d.DriveLetter & " - "

    If d.DriveType = Remote Then
    n = d.ShareName
    Else
    n = d.VolumeName
    End If

    s = s & n & vbCrLf
    Next
    MsgBox s

    err_handler_exit:
    Exit Sub

    err_handler:
    If (Err.Number = 71) Then 'Disk not ready must be empty floppy
    Resume Next
    Else
    Resume err_handler_exit
    End If
    End Sub


  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Geelong, Victoria, Australia
    Posts
    8

    Sharename

    Thanks for your comments Steven.

    I am trying to store a reference to documents (Word docs and Excel spreadsheets only at this stage) in a database so that anyone on the LAN can get at them.

    eg. My app starts the appropriate app, (Word or Excel) and opens the file the user chooses from a database. The user doesn't need to know where it is - as long it is stored on a shareable drive, they should be able to open it. Problem starts when a user creates a new document on their machine and saves it there - I can't find the Sharename in order to save that to the database, so other users can get at it. If other users, open the document from another PC's shared drive, it works fine as the sharename is known at that point.

    Regards.
    Stu.

  5. #5
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    My understanding so far is it seems a shared name will only be returned for a Network drive, not available from local machines.

    If object is not a network drive, the ShareName property returns a zero-length string ("").

    Sub ShowDriveInfo(drvpath)
    Dim fs, d, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set d = fs.GetDrive(fs.GetDriveName _
    (fs.GetAbsolutePathName(drvpath)))
    s = "Drive " & d.DriveLetter & ": - " & d.ShareName
    MsgBox s
    End Sub

    Or just get the path, but this is no use to you I know....

    For drive letters, the root drive is not included. For example, the path for the C drive is C:, not C:\. The following code illustrates the use of the Path property with a File object:

    Sub ShowFileAccessInfo(filespec)
    Dim fs, d, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(filespec)
    msgbox UCase(f.Path),,"File Path"
    End Sub


    You might be able to dynamically build a share name path by using API's to collect directory name/Machine name etc ??
    Hope this is of interest.

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