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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mapping Drives

Status
Not open for further replies.

KKit

Technical User
Jun 13, 2007
28
0
0
CA
I have an application for a customer that has 3 computers in their setup. They use computer A (the boss' computer) to double as a "server" for all their storage. Computers B and C are mapped to computer A for all documents.

In my application, they need to store links to certain files. When Computer B & C save the links and open them, no problem, as the link for everyone is exactly the same, and contains the computer name (by means of the code below).

The problem comes in when computer A saves a link. They, of course, will end up saving it as c:\, and the other computers can't open it up.

Can anyone tell me how I should be saving the links (and how to accomplish this in code), so that they all have the same thing?

I have a small routine that I am using to replace computer B & C mapping information with the computer name. What I don't know is how to get person A to use the name instead of C:!

Code:
Function MapDrivePath(sMapString As String)
    Dim wshNetwork
    Dim oDrives
    Dim oPrinters
    Dim ii As Integer
    Dim strTEMP As String
    Set wshNetwork = CreateObject("WScript.Network")
    Set oDrives = wshNetwork.EnumNetworkDrives()
    
    MapDrivePath = sMapString
    For ii = 0 To oDrives.Count - 1 Step 2
        strTEMP = oDrives.Item(ii)
        If strTEMP = Left(sMapString, 2) And sMapString <> "" Then
            MapDrivePath = oDrives.Item(ii + 1) & Mid(sMapString, 3, Len(sMapString) - 2)
            Debug.Print "Drive " & oDrives.Item(ii) & " = " & oDrives.Item(ii + 1)
        End If
    Next
End Function

Thanks to anyone that can help me out!
 
Can you not map the relevant folder on A? I have a shared folder mapped to mimic a network drive on Windows XP.
 
I tried your suggestion, and it looks like it does work. However, if the user chooses to use "my documents/folder name" to access the file and save the link, then it stores it as C:\. If they choose the mapped drive letter to access the file to save the link, then it works OK.

Any further suggestions for something a bit more foolproof (or user-proof!), so no matter what they choose, it will find the right file.

Thanks
 
Test for the required drive path in the file path and substitute if it is not found.
 
Can you use UNC file paths (\\ComputerName\ShareName...\FileName.ext) instead of drive letters? If all three computers store the paths this way then it shouldn't matter which machine the files reside on or are accessed from...

Ed Metcalfe.

Please do not feed the trolls.....
 
I think we are on a good path, but I need some help refining it.

If Computer A finds a picture and stores that link, they will store it at C:\Documents and Settings\All Users\Documents\ApplicationName\StaffPictures.

If Computer B finds that same picture and stores that link, they will store it as X:\ApplicationName\StaffPictures.

How do I use the UNC file paths (or other technique) to save the names globally. That is the part that is confusing me, I think.

My little routine will work when it is computer B doing it, as it recognzies the mapped name. But I am not certain how to get computer A's unc file path.

Does that make sense?
 
I've never actually done this so the following may not be entirely correct, but something along the lines of:

Assuming the local drive is shared on the boss's PC with a share name of C$ the destination directory can be addressed as:

\\A\C$\Documents and Settings\All Users\Documents\ApplicationName\StaffPictures\

You can get the boss's computer name from the environment variable COMPUTERNAME (Environ("COMPUTERNAME") in VBA). This will replace the "A" in the above file path. When he saves files you will need to replace the "C:\" portion of the file path with "\\A\C$\" (have a look at the VBA Replace() function). When other users save files they should access this directory through the UNC file path so you won't need to do anything with the path.

Hopefully then all users should be able to open files via the UNC path, regardless of which PC they are working on.

Ed Metcalfe.

Please do not feed the trolls.....
 
I couldn't quite get this to work. But doing all this research has certainly educated me on the UNC file path.

In the end, I replaced the file path name with the computer name. A little too "hard coded" for my liking, but 7 hours later, I am tired of looking for a better fix!

Thanks for both of your help!

L
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top