Getting past net use: i: /delete

Posted on 2009-02-09
Last Modified: 2012-05-06
I am trying to setup a login script to map an I: drive.

I have used this in the past with no problem:
@echo off
net use I: /delete
net use I: \\server1\share1

I will get "the network connection could not be found" if there is no mapping already. If there is a mapping that does exist for the I drive, it will not disconnect it and reconnect the new one to \\server1\share1.

Is there a way first delete a network drive and get past any errors if it's not already mapped so that the mapping can continue?

Question by:Ponthecomputer
    LVL 8

    Assisted Solution

    I have seen that happen when a drive is in "disconnected" state otherwise it should work and continue on.
    At the begining of your script delete all mapped drives first just incase?

    net use * /delete
    net use /persistent:no
    net use I: \\server1\share1
    LVL 1

    Assisted Solution

    Or in VBS if you prefer.
    This will remove all drives then add then back

    On Error Resume Next
          Set objNetwork = CreateObject("Wscript.Network")
          Set colDrives = objNetwork.EnumNetworkDrives
          For i = 0 to colDrives.Count-1 Step 2
                objNetwork.RemoveNetworkDrive colDrives.Item(i)
          objNetwork.MapNetworkDrive "i:" , "\\server1\share1"
          objNetwork.MapNetworkDrive "j:" , "\\server2\share2"
    LVL 27

    Accepted Solution


    if EXIST l: "net use I: /delete"
    net use I: \\server1\share1

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction: I have always been a big fan of Windows but my liking towards it is slowly being eroded by the variety of other Applications that I encounter, when I browse the Web. Most of the software available is free and maybe Open Source too. …
    Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now