Mapping network drive using bat file

Discussion in 'Computer and Electronic GadgetsZone' started by timmy1376, Nov 11, 2008.

  1. timmy1376

    timmy1376 Thread Starter Active SatelliteGuys Member

    Joined:
    May 20, 2004
    Posts:
    692
    Likes Received:
    0
    No problems mapping a network drive using a .bat file, but I cannot figure out for the life of me how to get the bat file to map to a folder in the share. I have a share called software and 20 folder in it called Lab 1 all the way to Lab 20

    for example:
    I do map network drives

    \\IP.IP.IP.IP\software\Lab 14

    and it works great, but trying to do that in a bat file, nothing happens

    \\IP.IP.IP.IP\software

    works great in the bat file.

    Anyone know how to get directly to that Lab 14 folder using a bat file?
     
    #1
  2. SatinKzo

    SatinKzo Supporting Founder
    Supporting Founder

    Joined:
    May 22, 2004
    Posts:
    6,013
    Likes Received:
    2
    net use x: \\ip.ip.ip.ip\share
    x: being the desired drive letter to assign.

    You can also delete the mapping

    net use x: /delete
    or
    net use x: /delete /y
    to delete and answer yes if a message requiring confirmation comes up.

    There are other more exotic ways to do it with different scripting languages.
     
    #2
  3. timmy1376

    timmy1376 Thread Starter Active SatelliteGuys Member

    Joined:
    May 20, 2004
    Posts:
    692
    Likes Received:
    0
    Got that, just cannot get the folder under the share to map using a bat file....

    but it maps fine using the Map Network drive tool
     
    #3
  4. SatinKzo

    SatinKzo Supporting Founder
    Supporting Founder

    Joined:
    May 22, 2004
    Posts:
    6,013
    Likes Received:
    2
    Should work fine even with a sub-dir of the shared directory

    example:

    net use x: \\ip.ip.ip.ip\share\subdir

    Just tested quicky and it works fine for me. What OS are we talking here? I assumed windows.

    If you wanted to get real fancy you could put a loop or similar in the batch file and map all 20 lab directories with just a couple lines in the batch file.
    Edit:
    OH, wait, do your lab directories look like this?

    Lab 14
    not
    Lab14
    ?

    The space is getting ya. Try this

    net use x: "\\ip.ip.ip.ip\share\subdir stuff"
     
    #4
  5. timmy1376

    timmy1376 Thread Starter Active SatelliteGuys Member

    Joined:
    May 20, 2004
    Posts:
    692
    Likes Received:
    0
    PERFECT!!!! Didn't eve consider the space messing me up.

    THANKS SO MUCH!!!!!!!!
     
    #5
  6. jon1nim

    jon1nim New Member

    Joined:
    Nov 28, 2008
    Posts:
    1
    Likes Received:
    0
    even better

    Set oShell = Createobject("wscript.shell") <enter>
    Set oNet = CreateObject("Wscript.Network") <enter>
    oNet.MapNetworkDrive "v:", "\\name of computer\name of share", True, "username", "password" <enter>
    if same computer copy line to \name of share"
    if new computer drive type the full line and username and password

    this will allow you to map network drives with different user names and passwords and you can customize it to fit as many shares as needed
     
    #6
        
VigLink badge
Sucuri