Getting past net use: i: /delete

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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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"
Lukasz ChmielewskiCommented:

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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.