Network Drive Mapping

Posted on 2011-03-08
Last Modified: 2012-05-11
I'm setting up a small bit of VBA Code to map a network drive if the path isn't available and i've got that to work but the mapping is showing up as
blank on 'UNC PATH'

rather then the usual
folder on 'UNC PATH'

is there anyway to fix that here is an example of the code

    Set wshNetwork = CreateObject("WScript.Network")
    Set colNetDrives = wshNetwork.EnumNetworkDrives
    For X = 71 To 90 'Letters G through Z
        DrvFound = False
        For Y = 1 To colNetDrives.Count - 1
            If colNetDrives.Item(Y) = Chr(X) & ":" Then
                DrvFound = True
            End If
        Next Y
        If Not DrvFound Then
            strDriveLtr = Chr(X) & ":"
            Exit For
        End If
    Next X
    wshNetwork.MapNetworkDrive strDriveLtr, sDRIVEMAPPING, True

End Sub
Question by:Thrawn3000
  • 3
LVL 44

Expert Comment

by:Jackie Man
ID: 35077469
Run a ipconfig /all in command prompt and post back the results.

Expert Comment

ID: 35077472
Not entirely sure what you are asking, but I don't see anything in your code that actually tells the system where to map the drive to. You can do that with the following code:

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "K:", "\\SERVERNAME\FOLDER"
                                               ^                           ^
                                          Drive Letter           Folder Location

Author Comment

ID: 35077649
Ok could better explain what i'm asking,

say i have the following UNC pathname


When mapped manually through the 'Map Network Drive..' feature in windows XP it becomes


when i use the code

wshNetwork.MapNetworkDrive strDriveLtr, sDRIVEMAPPING, True

strDriveLtr = the drive letter i'm assigning the map to
sDRIVEMAPPING = the UNC pathname

it comes up


LVL 44

Expert Comment

by:Jackie Man
ID: 35077847
LVL 44

Accepted Solution

Jackie Man earned 500 total points
ID: 35077856
You add an additional "\" after the UNC path.

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Seperate Windows 7 Purchases or Volume License... 13 205
Running VB6 Apps on Windows 7 4 144
Lock down IT Intern accounts 4 115
Need IE 6 on Win 7 or Win 10 23 105
Disclosure: Use this tutorial only when no other options helps to get Windows XP running without any problems and you don't want to format the drive. The back up of the data is the responsible of the user, however there is a description of how t…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 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