Closed Thread
Results 1 to 7 of 7

MapDrive Script Question

Hybrid View

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    MapDrive Script Question

    Hi,
    I have the following script:

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "X:" , "\\glbfil03\groups\Custchoice\Pratik\DailyCRMTasksDatabases"
    objNetwork.MapNetworkDrive "N:" , "\\GLANW001\DATA\Data\Common\Operational Resource And Reporting\PA\Data Files"
    objNetwork.MapNetworkDrive "B:" , "\\glbfil03\Groups\Custchoice\Pratik"
    objNetwork.MapNetworkDrive "W:" , "\\glbfil03\groups\Custchoice\Pratik\DailyRunRateDatabases"
    objNetwork.MapNetworkDrive "U:" , "\\10.216.2.31\DOS"
    How i amend the code to check if the drive is already mapped and if it is then to go onto the next drive..

    At the moment, if one of the drives is mapped, it doesnt map either of the other ones
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi Pr4t3ek,

    I haven't tried this myself, so I'm not sure it will even work, but it seemed promising. Supposedly this will unmap your drives, then remap them. Unfortunately I don't know how to check if a drive is already mapped, and if so leave it be.
    Set objNetwork = CreateObject("WScript.Network")
    With objNetwork
        .RemoveNetworkDrive "X:", True
        .RemoveNetworkDrive "N:", True
        .RemoveNetworkDrive "B:", True
        .RemoveNetworkDrive "W:", True
        .RemoveNetworkDrive "U:", True
        .MapNetworkDrive "X:", "\\glbfil03\groups\Custchoice\Pratik\DailyCRMTasksDatabases"
        .MapNetworkDrive "N:", "\\GLANW001\DATA\Data\Common\Operational Resource And Reporting\PA\Data Files"
        .MapNetworkDrive "B:", "\\glbfil03\Groups\Custchoice\Pratik"
        .MapNetworkDrive "W:", "\\glbfil03\groups\Custchoice\Pratik\DailyRunRateDatabases"
        .MapNetworkDrive "U:", "\\10.216.2.31\DOS"
    End With

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    Hi,
    It unmap's it just fine but doesn't map any of the drives

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello ,

    Here is a script to remap the drives. The limitation is this can only be on the local network. Change \\server1\share and \\server2\share to the old and new network paths you will be using.
    Set objNetwork = CreateObject("Wscript.Network")
    
    Set colDrives = objNetwork.EnumNetworkDrives
    
      For i = 0 to colDrives.Count-1 Step 2
          If colDrives.Item(i + 1) = "\\server1\share" Then
              strDriveLetter = colDrives.Item(i)
              objNetwork.RemoveNetworkDrive strDriveLetter
              objNetwork.MapNetworkDrive strDriveLetter, "\\server2\share"
          End If
      Next i
    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    Hey,
    And how would i go about assigning a username + password to a drive which i want to map.

    If i manually want to map a drive, i need to be logged in to the server, how can I go about this?

  6. #6
    Registered User
    Join Date
    03-16-2019
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    16

    Re: MapDrive Script Question

    Why doesn't this work for Windows 7?

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,700

    Re: MapDrive Script Question

    Administrative Note:

    Welcome to the forum.

    Given that this thread is over ten years old, so please start a new thread where we shall be happy to help.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Last edited by AliGW; 03-16-2019 at 04:15 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1